@Test public void testParseSingleResult() { FrequentlyRelatedItemSearchResponse[] responses = parser.parse(SINGLE_RESULT); assertEquals("Should only have one result",1,responses.length); assertFalse("Result should not be an error", responses[0].hasErrored()); assertEquals("Result should have 1 terms",1,responses[0].getNumberOfFacets()); assertEquals("Result should have 1 terms of '4'","4",responses[0].getFacetResult(0).name); assertEquals("Result should have 1 terms with count of '1002'",1002,responses[0].getFacetResult(0).count); }
@Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } }
JsonSmartFrequentlyRelatedItemHttpResponseParser implements FrequentlyRelatedItemHttpResponseParser { @Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } } }
JsonSmartFrequentlyRelatedItemHttpResponseParser implements FrequentlyRelatedItemHttpResponseParser { @Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } } JsonSmartFrequentlyRelatedItemHttpResponseParser(Configuration configuration); }
JsonSmartFrequentlyRelatedItemHttpResponseParser implements FrequentlyRelatedItemHttpResponseParser { @Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } } JsonSmartFrequentlyRelatedItemHttpResponseParser(Configuration configuration); @Override FrequentlyRelatedItemSearchResponse[] parse(String json); }
JsonSmartFrequentlyRelatedItemHttpResponseParser implements FrequentlyRelatedItemHttpResponseParser { @Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } } JsonSmartFrequentlyRelatedItemHttpResponseParser(Configuration configuration); @Override FrequentlyRelatedItemSearchResponse[] parse(String json);  }