List of usage examples for com.fasterxml.jackson.databind.node TreeTraversingParser TreeTraversingParser
public TreeTraversingParser(JsonNode n, ObjectCodec codec)
From source file:com.github.jonpeterson.jackson.module.interceptor.JsonInterceptingDeserializer.java
@Override public T deserialize(JsonParser parser, DeserializationContext context) throws IOException { JsonNode jsonNode = parser.readValueAsTree(); for (JsonInterceptor interceptor : interceptors) jsonNode = interceptor.intercept(jsonNode, context.getNodeFactory()); JsonParser postInterceptionParser = new TreeTraversingParser(jsonNode, parser.getCodec()); postInterceptionParser.nextToken();//from w w w . j ava 2 s. co m return delegate.deserialize(postInterceptionParser, context); }
From source file:com.github.jonpeterson.jackson.module.versioning.VersionedModelDeserializer.java
@Override public T deserialize(JsonParser parser, DeserializationContext context) throws IOException { JsonNode jsonNode = parser.readValueAsTree(); if (!(jsonNode instanceof ObjectNode)) throw context.mappingException("value must be a JSON object"); ObjectNode modelData = (ObjectNode) jsonNode; JsonNode modelVersionNode = modelData.remove(jsonVersionedModel.propertyName()); String modelVersion = null;/*w ww .j av a 2 s. c om*/ if (modelVersionNode != null) modelVersion = modelVersionNode.asText(); if (modelVersion == null) modelVersion = jsonVersionedModel.defaultDeserializeToVersion(); if (modelVersion.isEmpty()) throw context.mappingException("'" + jsonVersionedModel.propertyName() + "' property was null and defaultDeserializeToVersion was not set"); // convert the model if converter specified and model needs converting if (converter != null && (jsonVersionedModel.alwaysConvert() || !modelVersion.equals(jsonVersionedModel.currentVersion()))) modelData = converter.convert(modelData, modelVersion, jsonVersionedModel.currentVersion(), context.getNodeFactory()); // set the serializeToVersionProperty value to the source model version if the defaultToSource property is true if (serializeToVersionAnnotation != null && serializeToVersionAnnotation.defaultToSource()) modelData.put(serializeToVersionProperty.getName(), modelVersion); JsonParser postInterceptionParser = new TreeTraversingParser(modelData, parser.getCodec()); postInterceptionParser.nextToken(); return delegate.deserialize(postInterceptionParser, context); }