public static JsonPath from(String json) { return JsonPath.from(json).using(new DefaultJackson2ObjectMapperFactory() { public ObjectMapper create(Class cls, String charset) { return JacksonConfigurator.configureObjectMapper(super.create(cls, charset)); } }); }
private static <T> Object retrieveValueByPath(ContentProvider<T> contentProvider, Object o, String path) { String contentType = contentProvider.getContentType(o); String body = contentProvider.getValue(o); Object value; if (containsIgnoreCase(contentType, "xml")) { XmlPathConfig config = new XmlPathConfig().disableLoadingOfExternalDtd(); XmlPath xmlPath = new XmlPath(body); value = xmlPath.using(config).get(path); } else if (containsIgnoreCase(contentType, "html")) { XmlPath htmlPath = new XmlPath(XmlPath.CompatibilityMode.HTML, body); List<Object> list = htmlPath.getList(path); value = list.size() > 1 ? list : htmlPath.getString(path); } else { JsonPathConfig config = new JsonPathConfig().numberReturnType(JsonPathConfig.NumberReturnType.BIG_DECIMAL); JsonPath jsonPath = new JsonPath(body); value = jsonPath.using(config).get(path); } return value; }