本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.getNodeType方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.getNodeType方法的具体用法?Java JsonNode.getNodeType怎么用?Java JsonNode.getNodeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.getNodeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureParent
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static JsonNode ensureParent(JsonNode node, JsonPointer path, String typeName) {
/*
* Check the parent node: it must exist and be a container (ie an array
* or an object) for the add operation to work.
*/
final JsonPointer parentPath = path.head();
final JsonNode parentNode = node.at(parentPath);
if (parentNode.isMissingNode()) {
throw new JsonPatchException("non-existent " + typeName + " parent: " + parentPath);
}
if (!parentNode.isContainerNode()) {
throw new JsonPatchException(typeName + " parent is not a container: " + parentPath +
" (" + parentNode.getNodeType() + ')');
}
return parentNode;
}
示例2: treeTraversalSolution
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public void treeTraversalSolution() {
try {
ObjectMapper mapper = new ObjectMapper();
// use the ObjectMapper to read the json string and create a tree
JsonNode node = mapper.readTree(new File("Persons.json"));
Iterator<String> fieldNames = node.fieldNames();
while (fieldNames.hasNext()) {
JsonNode personsNode = node.get("persons");
Iterator<JsonNode> elements = personsNode.iterator();
while (elements.hasNext()) {
JsonNode element = elements.next();
JsonNodeType nodeType = element.getNodeType();
if (nodeType == JsonNodeType.STRING) {
out.println("Group: " + element.textValue());
}
if (nodeType == JsonNodeType.ARRAY) {
Iterator<JsonNode> fields = element.iterator();
while (fields.hasNext()) {
parsePerson(fields.next());
}
}
}
fieldNames.next();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:31,代码来源:JSONExamples.java
示例3: toStr
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* @param field
* @return
*/
private static Object toStr(final Map.Entry<String, JsonNode> field) {
JsonNode value = field.getValue();
switch (value.getNodeType()) {
case STRING:
return value.asText();
case NUMBER:
if (value.toString().contains(".")) {
return value.asDouble();
} else {
return value.asInt();
}
default:
return value.toString();
}
}
示例4: asValue
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public Object asValue(Object object) {
ObjectMapper objectMapper = getObjectMapper();
JsonNode node = objectMapper.convertValue(object, JsonNode.class);
if (node == null) {
return null;
}
switch (node.getNodeType()) {
case NUMBER:
return node.numberValue();
case STRING:
return node.textValue();
case BOOLEAN:
return node.booleanValue();
case ARRAY:
case BINARY:
case MISSING:
case NULL:
case OBJECT:
case POJO:
default:
return null;
}
}
示例5: isJsonNodeSubset
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的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
}
}
示例6: json2CanonicalString0
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static void json2CanonicalString0(final JsonNode node, final StringBuilder builder) {
switch (node.getNodeType()) {
case ARRAY:
array2CanonicalString(node, builder);
return;
case BINARY:
case BOOLEAN:
case NULL:
case NUMBER:
case STRING:
builder.append(node.toString());
return;
case OBJECT:
object2CanonicalString(node, builder);
return;
case POJO:
case MISSING:
throw new UnsupportedOperationException();
}
}
示例7: createSclarProperty
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private Property createSclarProperty(String arrayType, JsonNode node) {
Property property = null;
Iterator<JsonNode> nodes = node.elements();
while (nodes.hasNext()) {
JsonNode leafNode = nodes.next();
JsonNodeType type = leafNode.getNodeType();
switch (type) {
case STRING:
property = new StringPropertyBuilder().withExample(leafNode.asText()).build();
break;
case BOOLEAN:
property = new BooleanPropertyBuilder().withExample(leafNode.asBoolean()).build();
break;
case NUMBER:
if (leafNode.isInt() || leafNode.isLong()) {
property = new IntegerPropertyBuilder().withExample(leafNode.asLong()).build();
} else if (leafNode.isFloat() || leafNode.isDouble()) {
property = new NumberPropertyBuilder().withExample(leafNode.asDouble()).build();
}
break;
default:
break;
}
}
return property;
}
示例8: resolveNode
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private JsonNode resolveNode(LogEvent event, JsonNode node) {
JsonNodeType nodeType = node.getNodeType();
switch (nodeType) {
case ARRAY: return resolveArrayNode(event, node);
case OBJECT: return resolveObjectNode(event, node);
case STRING: return resolveStringNode(event, node);
default: return node;
}
}
示例9: loadObject
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private Object loadObject(JsonNode node) {
if (node == null) return null;
try {
switch (node.getNodeType()) {
case ARRAY:
return loadArray(node);
case BINARY:
return node.binaryValue();
case BOOLEAN:
return node.booleanValue();
case MISSING:
case NULL:
return null;
case NUMBER:
return node.numberValue();
case OBJECT:
return loadDocument(node);
case POJO:
return loadDocument(node);
case STRING:
return node.textValue();
}
} catch (IOException e) {
return null;
}
return null;
}
示例10: loadCredentials
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static List<MirrorCredential> loadCredentials(Map<String, Entry<?>> entries) throws Exception {
final Entry<?> e = entries.get(PATH_CREDENTIALS);
if (e == null) {
return Collections.emptyList();
}
final JsonNode credentialsJson = (JsonNode) e.content();
if (!credentialsJson.isArray()) {
throw new RepositoryMetadataException(
PATH_CREDENTIALS + " must be an array: " + credentialsJson.getNodeType());
}
if (credentialsJson.size() == 0) {
return Collections.emptyList();
}
final ImmutableList.Builder<MirrorCredential> builder = ImmutableList.builder();
for (JsonNode c : credentialsJson) {
final MirrorCredential credential = Jackson.treeToValue(c, MirrorCredential.class);
if (credential == null) {
throw new RepositoryMetadataException(PATH_CREDENTIALS + " contains null.");
}
builder.add(credential);
}
return builder.build();
}
示例11: generateDiffs
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static void generateDiffs(final DiffProcessor processor, final JsonPointer pointer,
final JsonNode source, final JsonNode target) {
if (EQUIVALENCE.equivalent(source, target)) {
return;
}
final JsonNodeType sourceType = source.getNodeType();
final JsonNodeType targetType = target.getNodeType();
/*
* Node types differ: generate a replacement operation.
*/
if (sourceType != targetType) {
processor.valueReplaced(pointer, source, target);
return;
}
/*
* If we reach this point, it means that both nodes are the same type,
* but are not equivalent.
*
* If this is not a container, generate a replace operation.
*/
if (!source.isContainerNode()) {
processor.valueReplaced(pointer, source, target);
return;
}
/*
* If we reach this point, both nodes are either objects or arrays;
* delegate.
*/
if (sourceType == JsonNodeType.OBJECT) {
generateObjectDiffs(processor, pointer, (ObjectNode) source, (ObjectNode) target);
} else {
// array
generateArrayDiffs(processor, pointer, (ArrayNode) source, (ArrayNode) target);
}
}
示例12: computeUnchanged
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static void computeUnchanged(final Map<JsonPointer, JsonNode> ret, final JsonPointer pointer,
final JsonNode source, final JsonNode target) {
if (EQUIVALENCE.equivalent(source, target)) {
ret.put(pointer, target);
return;
}
final JsonNodeType sourceType = source.getNodeType();
final JsonNodeType targetType = target.getNodeType();
if (sourceType != targetType) {
return; // nothing in common
}
// We know they are both the same type, so...
switch (sourceType) {
case OBJECT:
computeUnchangedObject(ret, pointer, source, target);
break;
case ARRAY:
computeUnchangedArray(ret, pointer, source, target);
break;
default:
/* nothing */
}
}
示例13: parseArtifact
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private BuckArtifact parseArtifact(Map.Entry<String, JsonNode> entry) {
String name = entry.getKey();
JsonNode value = entry.getValue();
String uri;
String repo = null;
if (value.isTextual()) {
uri = value.asText();
} else if (value.isObject()) {
uri = value.get("uri").asText();
repo = value.get("repo").asText("");
} else {
throw new RuntimeException("Unknown element for name: " + name +
" of type: " + value.getNodeType());
}
System.out.print(name + " ");
System.out.flush();
BuckArtifact buckArtifact;
if (uri.startsWith("http")) {
String sha = getHttpSha(uri);
buckArtifact = BuckArtifact.getArtifact(name, uri, sha);
} else if (uri.startsWith("mvn")) {
uri = uri.replaceFirst("mvn:", "");
// if (repo != null) {
// System.out.println(name + " " + repo);
// }
buckArtifact = AetherResolver.getArtifact(name, uri, repo);
} else {
throw new RuntimeException("Unsupported artifact uri: " + uri);
}
System.out.println(buckArtifact.url());
return buckArtifact;
}
示例14: deserialize
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public CiListRequest deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
if (node.getNodeType() == JsonNodeType.ARRAY) {
return new CiListRequest(getIds(node));
}
else {
JsonNode attrProps = node.get("attrProps");
JsonNode altNsTag = node.get("includeAltNs");
return new CiListRequest(getIds(node.get("ids")),
attrProps == null ? null :attrProps.asText(),
altNsTag == null ? null : altNsTag.asText());
}
}
示例15: deserialize
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public List<List<GeoCoord>> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
ObjectCodec codec = jp.getCodec();
JsonNode node = codec.readTree(jp);
if (JsonNodeType.ARRAY != node.getNodeType()) {
throw new IOException("Unable to instantiate new GeoCoord Path Lists from JSON!");
}
int nodeSize = node.size();
List<List<GeoCoord>> result = new ArrayList<>(nodeSize);
for (int i = 0; i < nodeSize; i++) {
JsonNode points = node.get(i);
int pointsSize = points.size();
List<GeoCoord> path = new ArrayList<>(pointsSize);
for (int j = 0; j < pointsSize; j++) {
JsonNode p = points.get(j);
double x = p.get(0).asDouble();
double y = p.get(1).asDouble();
path.add(new GeoCoord(x, y));
}
result.add(path);
}
return result;
}