本文整理匯總了Java中com.fasterxml.jackson.databind.node.ObjectNode.fields方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectNode.fields方法的具體用法?Java ObjectNode.fields怎麽用?Java ObjectNode.fields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.databind.node.ObjectNode
的用法示例。
在下文中一共展示了ObjectNode.fields方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isObjectNodeSubset
import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
/**
* Returns true if expected is a subset of returned
*
* This is used for JSON serialiser comparisons.
*
* @param expected
* @param returned
* @return
*/
protected boolean isObjectNodeSubset(ObjectNode expected, ObjectNode returned) {
Iterator<Entry<String, JsonNode>> expectedChildren = expected.fields();
for (Map.Entry<String, JsonNode> en; expectedChildren.hasNext();) {
en = expectedChildren.next();
String key = en.getKey();
JsonNode value = en.getValue();
JsonNode returnedValue = returned.get(key);
if (returnedValue == null) {
errorDescription = "Returned JSON does not have key '" + key +"', with expected value:\n" + value.toString();
return false;
} else if (!isJsonNodeSubset(value, returnedValue)) {
return false;
}
}
return true;
}
示例2: evalObject
import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
private void evalObject(ObjectNode source, ObjectNode target, RenderContext context,
ScriptContext scriptContext)
{
final Iterator<Entry<String, JsonNode>> it = source.fields();
while( it.hasNext() )
{
final Entry<String, JsonNode> e = it.next();
final String name = e.getKey();
final JsonNode n = e.getValue();
if( n.isObject() )
{
// recursively handle it
final ObjectNode nt = jsonMapper.createObjectNode();
target.put(name, nt);
evalObject((ObjectNode) n, nt, context, scriptContext);
}
else if( n.isInt() || n.isLong() )
{
target.put(name, n.asInt());
}
else if( n.isFloatingPointNumber() || n.isDouble() )
{
target.put(name, n.asDouble());
}
else if( n.isBoolean() )
{
target.put(name, n.asBoolean());
}
else if( n.isArray() )
{
target.putArray(name).addAll((ArrayNode) n);
}
else
{
// freemarker eval
target.put(name, evaluateMarkUp(context, n.asText(), scriptContext));
}
}
}
示例3: JsonObjectExpression
import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
protected JsonObjectExpression(ObjectNode o)
{
super();
final Iterator<Entry<String, JsonNode>> it = o.fields();
while( it.hasNext() )
{
final Entry<String, JsonNode> e = it.next();
final String name = e.getKey();
final JsonNode n = e.getValue();
if( n.isObject() )
{
put(name, new JsonObjectExpression((ObjectNode) n));
}
else if( n.isInt() )
{
put(name, n.asInt());
}
else if( n.isFloatingPointNumber() )
{
put(name, n.asDouble());
}
else if( n.isBoolean() )
{
put(name, n.asBoolean());
}
else
{
put(name, n.asText());
}
}
}
示例4: annotation
import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的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();
}