com.jayway.jsonpath.TypeRef Java Examples
The following examples show how to use
com.jayway.jsonpath.TypeRef.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiConnectorTemplate.java From syndesis with Apache License 2.0 | 5 votes |
private static ConnectorTemplate fetchSwaggerConnectorTemplateFromDeployment() { final Configuration configuration = Configuration.builder()// .jsonProvider(new JacksonJsonProvider(JsonUtils.copyObjectMapperConfiguration()))// .mappingProvider(new JacksonMappingProvider(JsonUtils.copyObjectMapperConfiguration()))// .build(); final List<ConnectorTemplate> templates = JsonPath.using(configuration) .parse(ApiConnectorTemplate.class.getResourceAsStream("/io/syndesis/server/dao/deployment.json")) .read("$..[?(@['id'] == 'swagger-connector-template')]", new TypeRef<List<ConnectorTemplate>>() { // type token pattern }); return templates.get(0); }
Example #2
Source File: SoapConnectorTemplate.java From syndesis with Apache License 2.0 | 5 votes |
private static ConnectorTemplate fetchSoapConnectorTemplateFromDeployment() { final Configuration configuration = Configuration.builder()// .jsonProvider(new JacksonJsonProvider(JsonUtils.copyObjectMapperConfiguration()))// .mappingProvider(new JacksonMappingProvider(JsonUtils.copyObjectMapperConfiguration()))// .build(); final List<ConnectorTemplate> templates = JsonPath.using(configuration) .parse(SoapConnectorTemplate.class.getResourceAsStream("/io/syndesis/server/dao/deployment.json")) .read("$..[?(@['id'] == 'soap-connector-template')]", new TypeRef<List<ConnectorTemplate>>() { // type token pattern }); return templates.get(0); }
Example #3
Source File: JsonbTest.java From ee8-sandbox with Apache License 2.0 | 5 votes |
@Test public void personToJsonString() { Person duke = new Person("Duke", LocalDate.of(1995, 5, 23)); duke.setPhoneNumbers( Arrays.asList( new PhoneNumber(HOME, "100000"), new PhoneNumber(OFFICE, "200000") ) ); Jsonb jsonMapper = JsonbBuilder.create(); String json = jsonMapper.toJson(duke); LOG.log(Level.INFO, "converted json result: {0}", json); String name = JsonPath.parse(json).read("$.name"); assertEquals("Duke", name); Configuration config = Configuration.defaultConfiguration() .jsonProvider(new GsonJsonProvider()) .mappingProvider(new GsonMappingProvider()); TypeRef<List<String>> typeRef = new TypeRef<List<String>>() { }; List<String> numbers = JsonPath.using(config).parse(json).read("$.phoneNumbers[*].number", typeRef); assertEquals(Arrays.asList("100000", "200000"), numbers); }
Example #4
Source File: JsonPathSelector.java From camunda-bpm-reactor with Apache License 2.0 | 5 votes |
@Override public <T> T map(Object source, TypeRef<T> targetType, Configuration configuration) { if (targetType.getType() instanceof Class) { return mapper.convertValue(source, (Class<T>) targetType.getType()); } else { throw new IllegalArgumentException("Cannot convert to " + targetType); } }
Example #5
Source File: JsonPathAssert.java From spring-cloud-open-service-broker with Apache License 2.0 | 4 votes |
public <T> ListAssert<T> hasListAtPath(String path) { TypeRef<List<T>> listTypeRef = new TypeRef<List<T>>() { }; return Assertions.assertThat(actual.read(path, listTypeRef)); }
Example #6
Source File: JsonPathAssert.java From spring-cloud-open-service-broker with Apache License 2.0 | 4 votes |
public <K, V> MapAssert<K, V> hasMapAtPath(String path) { TypeRef<Map<K, V>> mapTypeRef = new TypeRef<Map<K, V>>() { }; return Assertions.assertThat(actual.read(path, mapTypeRef)); }
Example #7
Source File: JSONMapParser.java From metron with Apache License 2.0 | 4 votes |
@Override public void configure(Map<String, Object> config) { setReadCharset(config); String strategyStr = (String) config.getOrDefault(MAP_STRATEGY_CONFIG, MapStrategy.DROP.name()); mapStrategy = MapStrategy.valueOf(strategyStr); overrideOriginalString = (Boolean) config.getOrDefault(OVERRIDE_ORIGINAL_STRING, false); if (config.containsKey(JSONP_QUERY)) { typeRef = new TypeRef<List<Map<String, Object>>>() { }; jsonpQuery = (String) config.get(JSONP_QUERY); if (!StringUtils.isBlank(jsonpQuery) && config.containsKey(WRAP_JSON)) { Object wrapObject = config.get(WRAP_JSON); if (wrapObject instanceof String) { wrapJson = Boolean.valueOf((String)wrapObject); } else if (wrapObject instanceof Boolean) { wrapJson = (Boolean) config.get(WRAP_JSON); } String entityName = (String)config.get(WRAP_ENTITY_NAME); if (!StringUtils.isBlank(entityName)) { wrapEntityName = entityName; } } Configuration.setDefaults(new Configuration.Defaults() { private final JsonProvider jsonProvider = new JacksonJsonProvider(); private final MappingProvider mappingProvider = new JacksonMappingProvider(); @Override public JsonProvider jsonProvider() { return jsonProvider; } @Override public MappingProvider mappingProvider() { return mappingProvider; } @Override public Set<Option> options() { return EnumSet.of(Option.SUPPRESS_EXCEPTIONS); } }); if (CacheProvider.getCache() == null) { CacheProvider.setCache(new LRUCache(100)); } } }