@Test void serializeNestedOrgJsonObjectWorks() { List<String> variants = new ArrayList<>(2); variants.add("{\"before\":[\"nothing\"],\"json\":{\"a\":\"b\",\"c\":true},\"after\":42}"); variants.add("{\"before\":[\"nothing\"],\"json\":{\"c\":true,\"a\":\"b\"},\"after\":42}"); org.json.JSONObject object = new org.json.JSONObject(); object.put("a", "b"); object.put("c", true); Map<String, Object> map = new LinkedHashMap<>(); map.put("before", Collections.singletonList("nothing")); map.put("json", object); map.put("after", 42); assertTrue(variants.contains(this.tool.serialize(map))); }
public String serialize(Object object) { try { ObjectMapper mapper = new ObjectMapper(); SimpleModule m = new SimpleModule("org.json.* serializer", new Version(1, 0, 0, "", "org.json", "json")); m.addSerializer(JSONObject.class, new JSONObjectSerializer()); m.addSerializer(JSONArray.class, new JSONArraySerializer()); mapper.registerModule(m); return mapper.writeValueAsString(object); } catch (JsonProcessingException e) { LOGGER.error("Failed to serialize object to JSON", e); } return null; }
JSONTool { public String serialize(Object object) { try { ObjectMapper mapper = new ObjectMapper(); SimpleModule m = new SimpleModule("org.json.* serializer", new Version(1, 0, 0, "", "org.json", "json")); m.addSerializer(JSONObject.class, new JSONObjectSerializer()); m.addSerializer(JSONArray.class, new JSONArraySerializer()); mapper.registerModule(m); return mapper.writeValueAsString(object); } catch (JsonProcessingException e) { LOGGER.error("Failed to serialize object to JSON", e); } return null; } }
JSONTool { public String serialize(Object object) { try { ObjectMapper mapper = new ObjectMapper(); SimpleModule m = new SimpleModule("org.json.* serializer", new Version(1, 0, 0, "", "org.json", "json")); m.addSerializer(JSONObject.class, new JSONObjectSerializer()); m.addSerializer(JSONArray.class, new JSONArraySerializer()); mapper.registerModule(m); return mapper.writeValueAsString(object); } catch (JsonProcessingException e) { LOGGER.error("Failed to serialize object to JSON", e); } return null; }  }
JSONTool { public String serialize(Object object) { try { ObjectMapper mapper = new ObjectMapper(); SimpleModule m = new SimpleModule("org.json.* serializer", new Version(1, 0, 0, "", "org.json", "json")); m.addSerializer(JSONObject.class, new JSONObjectSerializer()); m.addSerializer(JSONArray.class, new JSONArraySerializer()); mapper.registerModule(m); return mapper.writeValueAsString(object); } catch (JsonProcessingException e) { LOGGER.error("Failed to serialize object to JSON", e); } return null; }  String serialize(Object object); Object fromString(String str); @Deprecated JSON parse(String json); }
JSONTool { public String serialize(Object object) { try { ObjectMapper mapper = new ObjectMapper(); SimpleModule m = new SimpleModule("org.json.* serializer", new Version(1, 0, 0, "", "org.json", "json")); m.addSerializer(JSONObject.class, new JSONObjectSerializer()); m.addSerializer(JSONArray.class, new JSONArraySerializer()); mapper.registerModule(m); return mapper.writeValueAsString(object); } catch (JsonProcessingException e) { LOGGER.error("Failed to serialize object to JSON", e); } return null; }  String serialize(Object object); Object fromString(String str); @Deprecated JSON parse(String json);  }