本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.isValueNode方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.isValueNode方法的具体用法?Java JsonNode.isValueNode怎么用?Java JsonNode.isValueNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.isValueNode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getString
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
*
* 获取json传 K-V 的V值只适应于获取叶子节点的V值
* 注意:如果{"a":"b","c":{"d":"d1","e":{"f","f1"}}}
* 当 path为c时候,返回:{"d":"d1","e":{"f","f1"}}
* @param json
* @param paths
*
* @return
*/
public static String getString(@NotNull String json, @Nullable String... paths) {
JsonNode jsonNode = parseJsonNode(json, paths);
if (Check.isNull(jsonNode)) {
return null;
}
if(jsonNode.isValueNode()){
return jsonNode.textValue();
}
return toJsonString(jsonNode);
}
示例2: getColumnTypeFromJson
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* JsonNode like
* "flow_tables":{"type":{"key":{"maxInteger":254,"minInteger":0,"type":
* "integer"},"min":0,"value":{"type":"uuid","refTable":"Flow_Table"},"max":
* "unlimited"}}.
* @param columnTypeJson the ColumnType JsonNode
* @return ColumnType
*/
public static ColumnType getColumnTypeFromJson(JsonNode columnTypeJson) {
if (!columnTypeJson.isObject() || !columnTypeJson.has(Type.VALUE.type())) {
return createAtomicColumnType(columnTypeJson);
} else if (!columnTypeJson.isValueNode() && columnTypeJson.has(Type.VALUE.type())) {
return createKeyValuedColumnType(columnTypeJson);
}
String message = "Abnormal ColumnType JsonNode, it should be AtomicColumnType or KeyValuedColumnType"
+ ObjectMapperUtil.convertToString(columnTypeJson);
throw new AbnormalJsonNodeException(message);
}
示例3: getBaseTypeFromJson
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Create a BaseType from the JsonNode.
* @param baseTypeJson the BaseType JsonNode
* @param keyorval the key node or value node
* @return BaseType
*/
public static BaseType getBaseTypeFromJson(JsonNode baseTypeJson, String keyorval) {
if (baseTypeJson.isValueNode()) {
String type = baseTypeJson.asText().trim();
return fromTypeStr(type);
} else {
if (!baseTypeJson.has(keyorval)) {
String message = "Abnormal BaseType JsonNode, it should contain 'key' or 'value' node but was not found"
+ ObjectMapperUtil.convertToString(baseTypeJson);
throw new AbnormalJsonNodeException(message);
}
return fromJsonNode(baseTypeJson.get(keyorval));
}
}
示例4: isValueType
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public boolean isValueType(Object object) {
ObjectMapper objectMapper = getObjectMapper();
JsonNode node = objectMapper.convertValue(object, JsonNode.class);
return node != null && node.isValueNode();
}
示例5: flatten
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void flatten(JsonNode rootNode, Map<String, Object> map, boolean tooDeep)
{
for( Entry<String, JsonNode> child : Lists.newArrayList(rootNode.fields()) )
{
String key = child.getKey();
JsonNode value = child.getValue();
if( value.isValueNode() )
{
map.put(key, value.asText());
}
else if( value.isArray() )
{
for( int i = 0; i < value.size(); i++ )
{
JsonNode arrVal = value.get(i);
// Normal array
if( !arrVal.fields().hasNext() )
{
addToMap(map, key, arrVal);
}
else
{
addNodesToMap(map, key, arrVal);
}
}
}
else if( value.isObject() )
{
if( tooDeep )
{
addNodesToMap(map, key, value);
}
else
{
map.put(key, Maps.newLinkedHashMap());
flatten(value, (Map<String, Object>) map.get(key), true);
}
}
}
}
示例6: annotation
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Returns annotation of Ports on which LinkDiscovery is suppressed.
*
* @return key-value pairs of annotation
*/
public Map<String, String> annotation() {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
String jsonAnnotation = get(ANNOTATION, null);
if (jsonAnnotation == null || jsonAnnotation.isEmpty()) {
return ImmutableMap.of();
}
JsonNode annotationNode;
try {
annotationNode = MAPPER.readTree(jsonAnnotation);
} catch (IOException e) {
log.error("Failed to read JSON tree from: {}", jsonAnnotation);
return ImmutableMap.of();
}
if (annotationNode.isObject()) {
ObjectNode obj = (ObjectNode) annotationNode;
Iterator<Map.Entry<String, JsonNode>> it = obj.fields();
while (it.hasNext()) {
Map.Entry<String, JsonNode> entry = it.next();
final String key = entry.getKey();
final JsonNode value = entry.getValue();
if (value.isValueNode()) {
if (value.isNull()) {
builder.put(key, SuppressionRules.ANY_VALUE);
} else {
builder.put(key, value.asText());
}
} else {
log.warn("Encountered unexpected JSON field {} for annotation", entry);
}
}
} else {
log.error("Encountered unexpected JSONNode {} for annotation", annotationNode);
return ImmutableMap.of();
}
return builder.build();
}