本文整理汇总了Java中com.fasterxml.jackson.databind.node.ValueNode类的典型用法代码示例。如果您正苦于以下问题:Java ValueNode类的具体用法?Java ValueNode怎么用?Java ValueNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ValueNode类属于com.fasterxml.jackson.databind.node包,在下文中一共展示了ValueNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isJsonNodeSubset
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
/**
* Returns true if expected is a subset of returned
*
* This is used for JSON serialiser comparisons. This is taken from
* the 'equals' definition of JsonNode's, but without the length check
* on the list of children nodes, plus location reporting.
*
* @param expected
* @param returned
* @return
*/
protected boolean isJsonNodeSubset(JsonNode expected, JsonNode returned) {
if (returned == null) {
errorDescription = "Returned value is null, expected JSON:\n" + expected.toString();
return false;
}
if (returned == expected) return true;
if (returned.getClass() != expected.getClass()) {
errorDescription = "Returned value class is incorrect, expected JSON: " + expected.toString()
+ ", returned JSON: " + returned.toString();
return false;
}
switch (expected.getNodeType()) {
case ARRAY: return isArrayNodeSubset((ArrayNode)expected, (ArrayNode)returned);
case OBJECT: return isObjectNodeSubset((ObjectNode)expected, (ObjectNode)returned);
default: return isValueEqual((ValueNode)expected, (ValueNode)returned); // Will be a ValueNode subclass
}
}
示例2: jsonToMap
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
public void jsonToMap(String currentPath, JsonNode jsonNode, Map<String, String> map) {
if (jsonNode.isObject()) {
ObjectNode objectNode = (ObjectNode) jsonNode;
Iterator<Entry<String, JsonNode>> iter = objectNode.fields();
String pathPrefix = currentPath.isEmpty() ? "" : currentPath + ".";
while (iter.hasNext()) {
Entry<String, JsonNode> entry = iter.next();
jsonToMap(pathPrefix + entry.getKey(), entry.getValue(), map);
}
} else if (jsonNode.isArray()) {
ArrayNode arrayNode = (ArrayNode) jsonNode;
for (int i = 0; i < arrayNode.size(); i++) {
jsonToMap(currentPath + "." + i, arrayNode.get(i), map);
}
} else if (jsonNode.isValueNode()) {
ValueNode valueNode = (ValueNode) jsonNode;
map.put(currentPath, valueNode.asText());
}
}
示例3: buildQueryString
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
private void buildQueryString(URIBuilder url, String path, ObjectNode node) {
Iterator<Entry<String, JsonNode>> iterator = node.fields();
while (iterator.hasNext()) {
Entry<String, JsonNode> field = iterator.next();
String fieldName = field.getKey();
JsonNode childNode = field.getValue();
if (childNode instanceof ObjectNode) {
buildQueryString(url, getPath(path, fieldName), (ObjectNode) childNode);
} else if (childNode instanceof ValueNode) {
ValueNode valueNode = (ValueNode) childNode;
if (!valueNode.isNull()) {
url.addParameter(getPath(path, fieldName), valueNode.asText());
}
}
}
}
示例4: addKeys
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
private void addKeys(String currentPath, JsonNode jsonNode, Map<Object, Object> props) {
if (jsonNode.isObject()) {
ObjectNode objectNode = (ObjectNode) jsonNode;
Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields();
String pathPrefix = currentPath.isEmpty() ? "" : currentPath + ".";
while (iter.hasNext()) {
Map.Entry<String, JsonNode> entry = iter.next();
addKeys(pathPrefix + entry.getKey(), entry.getValue(), props);
}
} else if (jsonNode.isArray()) {
ArrayNode arrayNode = (ArrayNode) jsonNode;
for (int i = 0; i < arrayNode.size(); i++) {
addKeys(currentPath + "[" + i + "]", arrayNode.get(i), props);
}
} else if (jsonNode.isValueNode()) {
ValueNode valueNode = (ValueNode) jsonNode;
if(isAllowOverride || !props.containsKey(currentPath))
props.put(currentPath, valueNode.asText());
}
}
示例5: toValueNode
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
@Deprecated
public static ValueNode toValueNode(Object value) {
if (value == null)
return NullNode.instance;
if (value instanceof ValueNode)
return (ValueNode) value;
if (value instanceof Boolean)
return BooleanNode.valueOf((boolean) value);
else if (value instanceof Integer)
return IntNode.valueOf((int) value);
else if (value instanceof Long)
return LongNode.valueOf((long) value);
else if (value instanceof Double)
return DoubleNode.valueOf((double) value);
else if (value instanceof Float)
return FloatNode.valueOf((float) value);
return TextNode.valueOf(value.toString());
}
示例6: toValueNode
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
public static ValueNode toValueNode(Object value) {
if (value == null)
return NullNode.instance;
if (value instanceof ValueNode)
return (ValueNode) value;
if (value instanceof Boolean)
return BooleanNode.valueOf((boolean) value);
else if (value instanceof Integer)
return IntNode.valueOf((int) value);
else if (value instanceof Long)
return LongNode.valueOf((long) value);
else if (value instanceof Double)
return DoubleNode.valueOf((double) value);
else if (value instanceof Float)
return FloatNode.valueOf((float) value);
return TextNode.valueOf(value.toString());
}
示例7: request
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
/**
* Creates a new JSON-RPC request as a JSON object
*
* @param id request id
* @param method request method
* @param params request params
* @return a new request as a JSON object
*/
@NotNull
protected ObjectNode request(@NotNull ValueNode id, @NotNull String method,
@NotNull JsonNode params) {
if (method.isEmpty()) {
throw new IllegalArgumentException("Method is not set");
}
ObjectNode requestNode = mapper.createObjectNode();
requestNode.put(JSONRPC, VERSION_2_0);
requestNode.put(METHOD, method);
requestNode.set(PARAMS, params);
if (!id.isNull()) {
requestNode.set(ID, id);
}
return requestNode;
}
示例8: buildConfigFor
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
private static void buildConfigFor(String path, Map<String, String> config, JsonNode node) {
for (Iterator<Map.Entry<String, JsonNode>> i = node.fields(); i.hasNext();) {
Map.Entry<String, JsonNode> field = i.next();
if (field.getValue() instanceof ValueNode) {
ValueNode valueNode = (ValueNode) field.getValue();
config.put(DOT_JOINER.join(path, field.getKey()), valueNode.asText());
} else if (field.getValue() instanceof ArrayNode) {
StringBuilder combinedValue = new StringBuilder();
ArrayNode arrayNode = (ArrayNode) field.getValue();
for (Iterator<JsonNode> it = arrayNode.elements(); it.hasNext();) {
String value = it.next().asText().replaceAll("^\"|\"$", "");
if (combinedValue.length() > 0)
combinedValue.append(',');
combinedValue.append(value);
}
config.put(DOT_JOINER.join(path, field.getKey()), combinedValue.toString());
}
buildConfigFor(DOT_JOINER.join(path, field.getKey()), config, field.getValue());
}
}
示例9: fromJson
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
public static void fromJson(WithIfCurrent dest,ObjectNode node) {
JsonNode x=node.get("onlyIfCurrent");
if(x instanceof ValueNode && x.booleanValue()) {
dest.setIfCurrentOnly(true);
x=node.get("documentVersions");
if(x instanceof ArrayNode) {
List<String> versions=new ArrayList<>(x.size());
for(Iterator<JsonNode> itr=x.elements();itr.hasNext();) {
JsonNode elem=itr.next();
if(!(elem instanceof NullNode)) {
versions.add(elem.asText());
}
}
dest.setDocumentVersions(versions);
}
} else {
dest.setIfCurrentOnly(false);
}
}
示例10: valueFromJson
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
/**
* Returns a Java object for a json value node based on the node type.
*/
public static Object valueFromJson(ValueNode node) {
if (node instanceof NullNode) {
return null;
} else {
if(node instanceof TextNode) {
return node.textValue();
} else if(node instanceof BooleanNode) {
return node.booleanValue();
} else if(node instanceof NumericNode) {
return node.numberValue();
} else {
throw new RuntimeException("Unsupported node type:"+node.getClass().getName());
}
}
}
示例11: isValueEqual
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
protected boolean isValueEqual(ValueNode expected, ValueNode returned) {
boolean result = returned.equals(expected);
if (!result) {
errorDescription = "Expected value: '" + expected.toString() + "', returned value: '" + returned.toString() + "' are not equal";
}
return result;
}
示例12: equals
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
@Override
protected boolean equals(ValueNode value1,ValueNode value2) {
if(value1.isNumber()&&value2.isNumber()) {
return value1.asText().equals(value2.asText());
} else {
return value1.equals(value2);
}
}
示例13: deserializeObject
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
private Duration deserializeObject(TreeNode tree, DeserializationContext c)
throws JsonMappingException {
if (tree == null) {
throw c.mappingException("expected object");
}
TreeNode node;
ValueNode valueNode;
final long duration;
final TimeUnit unit;
if ((node = tree.get("duration")) != null && node.isValueNode() &&
(valueNode = (ValueNode) node).isNumber()) {
duration = valueNode.asLong();
} else {
throw c.mappingException("duration is not a numeric field");
}
if ((node = tree.get("unit")) != null && node.isValueNode() &&
(valueNode = (ValueNode) node).isTextual()) {
unit = TimeUnit.valueOf(valueNode.asText().toUpperCase());
} else {
unit = Duration.DEFAULT_UNIT;
}
return new Duration(duration, unit);
}
示例14: flattenJsonIntoMap
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
public void flattenJsonIntoMap(String currentPath, JsonNode jsonNode, Map<String, Object> map) {
if (jsonNode.isObject()) {
ObjectNode objectNode = (ObjectNode) jsonNode;
Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields();
String pathPrefix = currentPath.isEmpty() ? "" : currentPath + ".";
while (iter.hasNext()) {
Map.Entry<String, JsonNode> entry = iter.next();
flattenJsonIntoMap(pathPrefix + entry.getKey(), entry.getValue(), map);
}
} else if (jsonNode.isArray()) {
ArrayNode arrayNode = (ArrayNode) jsonNode;
for (int i = 0; i < arrayNode.size(); i++) {
flattenJsonIntoMap(currentPath + "[" + i + "]", arrayNode.get(i), map);
}
} else if (jsonNode.isValueNode()) {
ValueNode valueNode = (ValueNode) jsonNode;
Object value = null;
if (valueNode.isNumber()) {
value = valueNode.numberValue();
} else if (valueNode.isBoolean()) {
value = valueNode.asBoolean();
} else if (valueNode.isTextual()){
value = valueNode.asText();
}
map.put(currentPath, value);
}
}
示例15: flattenJsonTree
import com.fasterxml.jackson.databind.node.ValueNode; //导入依赖的package包/类
private void flattenJsonTree(String currentPath, JsonNode jsonNode, ByteArrayOutputStream out)
throws SerializationException {
if (jsonNode.isObject()) {
ObjectNode objectNode = (ObjectNode) jsonNode;
Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields();
String pathPrefix = currentPath.isEmpty() ? "" : currentPath + ".";
while (iter.hasNext()) {
Map.Entry<String, JsonNode> entry = iter.next();
flattenJsonTree(pathPrefix + entry.getKey(), entry.getValue(), out);
}
} else if (jsonNode.isArray()) {
throw new SerializationException("Arrays in JSON are not supported yet.");
} else if (jsonNode.isValueNode()) {
ValueNode valueNode = (ValueNode) jsonNode;
if (!fieldMapping.containsField(currentPath)) {
fieldMapping.put(currentPath, delimiters[currentDelimiterIdx++], getNodeType(jsonNode));
} else {
DataType existingType = fieldMapping.getDataType(currentPath);
DataType newType = getNodeType(valueNode);
if (existingType != newType) {
DataType encapsulatingType = DataType.encapsulatingType(existingType, newType);
fieldMapping.updateType(currentPath, encapsulatingType);
}
}
try {
byte fieldByte = fieldMapping.getDelimiter(currentPath);
out.write(fieldByte);
out.write(valueNode.asText().getBytes());
out.write(fieldByte);
} catch (IOException e) {
throw new SerializationException(e.getMessage());
}
}
}