本文整理汇总了Java中com.jayway.jsonpath.TypeRef类的典型用法代码示例。如果您正苦于以下问题:Java TypeRef类的具体用法?Java TypeRef怎么用?Java TypeRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeRef类属于com.jayway.jsonpath包,在下文中一共展示了TypeRef类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: personToJsonString
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
@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);
}
示例2: fetchSwaggerConnectorTemplateFromDeployment
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
private static ConnectorTemplate fetchSwaggerConnectorTemplateFromDeployment() {
final Configuration configuration = Configuration.builder()//
.jsonProvider(new JacksonJsonProvider(Json.mapper()))//
.mappingProvider(new JacksonMappingProvider(Json.mapper()))//
.build();
final List<ConnectorTemplate> templates = JsonPath.using(configuration)
.parse(AbstractSwaggerConnectorTest.class.getResourceAsStream("/io/syndesis/dao/deployment.json"))
.read("$..[?(@['id'] == 'swagger-connector-template')]", new TypeRef<List<ConnectorTemplate>>() {
// type token pattern
});
return templates.get(0);
}
示例3: map
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
@Override
public <T> T map(Object source, final TypeRef<T> targetType, Configuration configuration) {
if(source == null){
return null;
}
JavaType type = objectMapper.getTypeFactory().constructType(targetType.getType());
try {
return (T)objectMapper.convertValue(source, type);
} catch (Exception e) {
throw new MappingException(e);
}
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:15,代码来源:JacksonMappingProvider.java
示例4: map
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
@Override
public <T> T map(Object source, TypeRef<T> targetType, Configuration configuration) {
if(source == null){
return null;
}
try {
return (T) factory.call().getAdapter(TypeToken.get(targetType.getType())).fromJsonTree((JsonElement) source);
} catch (Exception e){
throw new MappingException(e);
}
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:12,代码来源:GsonMappingProvider.java
示例5: map
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
@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);
}
}
示例6: select
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
@Override
public <U> List<U> select(String value, DataConverter<String, U> converter) {
try {
List<String> results = context.read(evaluations.get(value), new TypeRef<List<String>>() {
});
return results.stream().map(el -> converter.convert(el)).collect(Collectors.toList());
} catch (ExecutionException e) {
throw Throwables.propagate(e);
}
}
示例7: map
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
@Override
public <T> T map(final Object source, final TypeRef<T> targetType, final Configuration configuration) {
throw new UnsupportedOperationException(
"Tapestry JSON provider does not support TypeRef! Use a Jackson or Gson based provider");
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:6,代码来源:TapestryMappingProvider.java
示例8: map
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
@Override
public <T> T map(Object source, TypeRef<T> targetType, Configuration configuration) {
throw new UnsupportedOperationException("Json-smart provider does not support TypeRef! Use a Jackson or Gson based provider");
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:5,代码来源:JsonSmartMappingProvider.java
示例9: map
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
@Override
public <T> T map(Object source, TypeRef<T> targetType, Configuration configuration) {
throw new UnsupportedOperationException("JsonOrg provider does not support TypeRef! Use a Jackson or Gson based provider");
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:5,代码来源:JsonOrgMappingProvider.java
示例10: read
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
@Override
public <T> T read(JsonPath path, TypeRef<T> type) {
return convert(read(path), type, configuration);
}
示例11: convert
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
private <T> T convert(Object obj, TypeRef<T> targetType, Configuration configuration){
return configuration.mappingProvider().map(obj, targetType, configuration);
}
示例12: jsonPathAsListOf
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
/**
* Extracts a JSON array using a JsonPath expression and wrap it in a {@link ListAssert}. This method requires
* the JsonPath to be <a href="https://github.com/jayway/JsonPath#jsonprovider-spi">configured with Jackson or
* Gson</a>.
*
* @param path JsonPath to extract the array
* @param type The type to cast the content of the array, i.e.: {@link String}, {@link Integer}
* @return an instance of {@link ListAssert}
*/
public <T> AbstractListAssert<?, ? extends List<? extends T>, T> jsonPathAsListOf(String path, Class<T> type) {
return Assertions.assertThat(actual.read(path, new TypeRef<List<T>>() {
}));
}
示例13: map
import com.jayway.jsonpath.TypeRef; //导入依赖的package包/类
/**
*
* @param source object to map
* @param targetType the type the source object should be mapped to
* @param configuration current configuration
* @param <T> the mapped result type
* @return return the mapped object
*/
<T> T map(Object source, TypeRef<T> targetType, Configuration configuration);