private ContainerFactory createContainerFactory() { return new ContainerFactory() { @Override public Map createObjectContainer() { return new LinkedHashMap(); } @Override public List creatArrayContainer() { return new LinkedList(); } }; }
private void createJsonParser() { this.parser = new JSONParser(); containerFactory = new ContainerFactory() { @Override public List creatArrayContainer() { return new LinkedList(); } @Override public Map createObjectContainer() { return new LinkedHashMap(); } }; }
@SuppressWarnings({ "rawtypes", "unchecked" }) private void initialize() { try { JSONParser parser = new JSONParser(); ContainerFactory containerFactory = new ContainerFactory() { public List creatArrayContainer() { return new LinkedList(); } public Map createObjectContainer() { return new LinkedHashMap(); } }; if (!StringUtils.isEmpty(this.response)) { Object parse = parser.parse(this.response, containerFactory); if (parse instanceof List) { this.jsonMap = new LinkedHashMap(); } else { this.jsonMap = (Map) parse; } this.jsonMap.put("root", parse); } else { this.jsonMap = new HashMap(); } } catch (Exception ex) { logger.warn("Unable to parse the response string as a JSON object: " + this.response, ex); } }
@SuppressWarnings("rawtypes") private Map createObjectContainer(ContainerFactory containerFactory) { if (containerFactory == null) return new JSONObject(); Map m = containerFactory.createObjectContainer(); if (m == null) return new JSONObject(); return m; }
@SuppressWarnings("rawtypes") private List createArrayContainer(ContainerFactory containerFactory) { if (containerFactory == null) return new JSONArray(); List l = containerFactory.creatArrayContainer(); if (l == null) return new JSONArray(); return l; }