• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TypeRef类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
}
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:29,代码来源:JsonbTest.java


示例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);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:15,代码来源:AbstractSwaggerConnectorTest.java


示例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);
  }
}
 
开发者ID:camunda,项目名称:camunda-bpm-reactor,代码行数:9,代码来源:JsonPathSelector.java


示例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);
	}
}
 
开发者ID:Treydone,项目名称:mandrel,代码行数:11,代码来源:JsonSelector.java


示例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);
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:5,代码来源:JsonContext.java


示例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);
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:4,代码来源:JsonContext.java


示例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>>() {
    }));
}
 
开发者ID:revinate,项目名称:assertj-json,代码行数:14,代码来源:JsonPathAssert.java


示例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);
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:10,代码来源:MappingProvider.java



注:本文中的com.jayway.jsonpath.TypeRef类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Factory类代码示例发布时间:2022-05-22
下一篇:
Java TimerListener类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap