本文整理了Java中com.jayway.jsonpath.spi.json.JsonProvider.toJson()
方法的一些代码示例,展示了JsonProvider.toJson()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonProvider.toJson()
方法的具体详情如下:
包路径:com.jayway.jsonpath.spi.json.JsonProvider
类名称:JsonProvider
方法名:toJson
[英]Convert given json object to a json string
[中]将给定的json对象转换为json字符串
代码示例来源:origin: json-path/JsonPath
@Override
public String jsonString() {
return configuration.jsonProvider().toJson(json);
}
代码示例来源:origin: apache/nifi
static String getResultRepresentation(Object jsonPathResult, String defaultValue) {
if (isJsonScalar(jsonPathResult)) {
return Objects.toString(jsonPathResult, defaultValue);
}
return JSON_PROVIDER.toJson(jsonPathResult);
}
代码示例来源:origin: apache/nifi
static String getResultRepresentation(final Object jsonPathResult, final String defaultValue) {
if (isJsonScalar(jsonPathResult)) {
return Objects.toString(jsonPathResult, defaultValue);
} else if (jsonPathResult instanceof List && ((List<?>) jsonPathResult).size() == 1) {
return getResultRepresentation(((List<?>) jsonPathResult).get(0), defaultValue);
} else {
return JSON_PROVIDER.toJson(jsonPathResult);
}
}
代码示例来源:origin: json-path/JsonPath
@Override
public <T> T map(Object source, Class<T> targetType, Configuration configuration) {
if(source == null){
return null;
}
if (targetType.isAssignableFrom(source.getClass())) {
return (T) source;
}
try {
if(!configuration.jsonProvider().isMap(source) && !configuration.jsonProvider().isArray(source)){
return factory.call().getMapper(targetType).convert(source);
}
String s = configuration.jsonProvider().toJson(source);
return (T) JSONValue.parse(s, targetType);
} catch (Exception e) {
throw new MappingException(e);
}
}
代码示例来源:origin: json-path/JsonPath
@Test
public void issue_36() {
String json = "{\n" +
"\n" +
" \"arrayOfObjectsAndArrays\" : [ { \"k\" : [\"json\"] }, { \"k\":[\"path\"] }, { \"k\" : [\"is\"] }, { \"k\" : [\"cool\"] } ],\n" +
"\n" +
" \"arrayOfObjects\" : [{\"k\" : \"json\"}, {\"k\":\"path\"}, {\"k\" : \"is\"}, {\"k\" : \"cool\"}]\n" +
"\n" +
" }";
Object o1 = read(json, "$.arrayOfObjectsAndArrays..k ");
Object o2 = read(json, "$.arrayOfObjects..k ");
assertEquals("[[\"json\"],[\"path\"],[\"is\"],[\"cool\"]]", jp.toJson(o1));
assertEquals("[\"json\",\"path\",\"is\",\"cool\"]", jp.toJson(o2));
}
代码示例来源:origin: json-path/JsonPath
result = res.toString();
} else {
result = res != null ? Configuration.defaultConfiguration().jsonProvider().toJson(res) : "null";
代码示例来源:origin: com.jayway.jsonpath/json-path
@Override
public String jsonString() {
return configuration.jsonProvider().toJson(json);
}
代码示例来源:origin: com.jayway.jsonpath/json-path
@Override
public <T> T map(Object source, Class<T> targetType, Configuration configuration) {
if(source == null){
return null;
}
if (targetType.isAssignableFrom(source.getClass())) {
return (T) source;
}
try {
if(!configuration.jsonProvider().isMap(source) && !configuration.jsonProvider().isArray(source)){
return factory.call().getMapper(targetType).convert(source);
}
String s = configuration.jsonProvider().toJson(source);
return (T) JSONValue.parse(s, targetType);
} catch (Exception e) {
throw new MappingException(e);
}
}
代码示例来源:origin: org.apache.calcite/calcite-core
public static String jsonize(Object input) {
return JSON_PATH_JSON_PROVIDER.toJson(input);
}
代码示例来源:origin: com.hurence.logisland/logisland-common-processors-plugin
static String getResultRepresentation(Object jsonPathResult, String defaultValue) {
if (isJsonScalar(jsonPathResult)) {
return Objects.toString(jsonPathResult, defaultValue);
}
return JSON_PROVIDER.toJson(jsonPathResult);
}
代码示例来源:origin: org.apache.nifi/nifi-standard-processors
static String getResultRepresentation(Object jsonPathResult, String defaultValue) {
if (isJsonScalar(jsonPathResult)) {
return Objects.toString(jsonPathResult, defaultValue);
}
return JSON_PROVIDER.toJson(jsonPathResult);
}
代码示例来源:origin: com.github.lafa.jsonpath/json-path
@Override
public String jsonString() {
return configuration.jsonProvider().toJson(json);
}
代码示例来源:origin: com.github.lafa.jsonpath/json-path
@Override
public <T> T map(Object source, Class<T> targetType, Configuration configuration) {
if(source == null){
return null;
}
if (targetType.isAssignableFrom(source.getClass())) {
return (T) source;
}
try {
if(!configuration.jsonProvider().isMap(source) && !configuration.jsonProvider().isArray(source)){
return factory.call().getMapper(targetType).convert(source);
}
String s = configuration.jsonProvider().toJson(source);
return (T) JSONValue.parse(s, targetType);
} catch (Exception e) {
throw new MappingException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!