This project is a simple Java Domain Object Model of the response's from a FACTFinder Service. We parse the response with Gson for easy use in your projects.
Just create a FactFinderParser Object and give it the JSON String and which Service response to parse.
String json = "...";//form the FactFinder response
FactFinderParser parser = new FactFinderGsonParser();
SearchResponse searchResult = (SearchResponse) parser.parse(json, FactFinderGsonParser.SERVICE_SEARCH);
//work with searchResult...
String jsonAgain = parser.asJson(parse);
We have Response classes for all the suported FACTFinder services:
SearchResponse.class;
SuggestResponse.class;
RecommendationResponse.class;
SimilarRecordsResponse.class;
ProductCampaignResponse.class;
You can quickly access them with the static constants in the FactFinderParser, for example:
FactFinderParser.SERVICE_SEARCH
In combination with the java-proxy-utils project, you can quickly find the right service of each request:
private ProxyUtils utils = new ProxyUtils(settings);
private FactFinderParser parser = new FactFinderGsonParser();
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
utils.copyHeaders(req, resp);
FACTFinderService service = utils.extractService(req);
String json = utils.sendRequest(req).getData();
Class<?> serviceClass = parser.getServiceResponseClass(service.name());
SearchResponse searchResult = (SearchResponse) parser.parse(json,serviceClass);
//work with searchResult...
}
If you want to customize the parsing settings, you can just initialize the FactFinderGsonParser with a 'Gson' Object:
GsonBuilder builder = new GsonBuilder()
builder.serializeNulls();
//builder.setSomeOtherSettings...
Gson gson = builder.create()
FactFinderParser parser = FactFinderGsonParser(gson);
In the /src/main/resources folder are all the JSON schema files the FACTFinder services. If you want you can generate some POJO's from them with the jsonschema2pojo-maven-plugin which is commented in the pom.xml Just uncomment hte plugin and the two dependencie's commons-lang and jackson-databind and run maven with:
mvn generate
You can define where the generated POJO's are located in the plugin configuration. For more info see: jsonschema2pojo