I need to implement a parser which parses some values from "JSON strings". The data is accessible from the request parameters as follows:
String[] criterion = request.getParameterValues("criteria");
The criterion contains the following strings (each row represents a String):
{"fieldName":"name","operator":"iContains","value":"a string"}
{"fieldName":"date","operator":"equals","value":"2013-02-26"}
{"fieldName":"amount","operator":"equals","value":2600}
I need to be able to get the values from criterion by fieldName. The API could be like this:
String name = CoolParserUtil.parseParam(criterion, "name", String.class);
// "a string"
Date date = CoolParserUtil.parseParam(criterion, "date", Date.class);
// date representing 2013-02-26
// etc. etc.
How would you implement the parser?