本文整理汇总了Java中com.jayway.jsonpath.spi.mapper.GsonMappingProvider类的典型用法代码示例。如果您正苦于以下问题:Java GsonMappingProvider类的具体用法?Java GsonMappingProvider怎么用?Java GsonMappingProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GsonMappingProvider类属于com.jayway.jsonpath.spi.mapper包,在下文中一共展示了GsonMappingProvider类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: personToJsonString
import com.jayway.jsonpath.spi.mapper.GsonMappingProvider; //导入依赖的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: removeJSONPathElement
import com.jayway.jsonpath.spi.mapper.GsonMappingProvider; //导入依赖的package包/类
/**
* Remove a subelement in a JsonPath
*
* @param jsonString String of the json
* @param expr regex to be removed
*/
public String removeJSONPathElement(String jsonString, String expr) {
Configuration conf = Configuration.builder().jsonProvider(new GsonJsonProvider()).mappingProvider(new GsonMappingProvider()).build();
DocumentContext context = JsonPath.using(conf).parse(jsonString);
context.delete(expr);
return context.jsonString();
}