Exemplo n.º 1
0
 /** Actual implementation of value reading+binding operation. */
 protected Object _bind(JsonParser jp)
     throws IOException, JsonParseException, JsonMappingException {
   /* First: may need to read the next token, to initialize state (either
    * before first read from parser, or after previous token has been cleared)
    */
   Object result;
   JsonToken t = _initForReading(jp);
   if (t == JsonToken.VALUE_NULL) {
     if (_valueToUpdate == null) {
       result = _findRootDeserializer(_config, _valueType).getNullValue();
     } else {
       result = _valueToUpdate;
     }
   } else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
     result = _valueToUpdate;
   } else { // pointing to event other than null
     DeserializationContext ctxt = _createDeserializationContext(jp, _config);
     JsonDeserializer<Object> deser = _findRootDeserializer(_config, _valueType);
     if (_unwrapRoot) {
       result = _unwrapAndDeserialize(jp, ctxt, _valueType, deser);
     } else {
       if (_valueToUpdate == null) {
         result = deser.deserialize(jp, ctxt);
       } else {
         deser.deserialize(jp, ctxt, _valueToUpdate);
         result = _valueToUpdate;
       }
     }
   }
   // Need to consume the token too
   jp.clearCurrentToken();
   return result;
 }
Exemplo n.º 2
0
 protected JsonNode _bindAsTree(JsonParser jp)
     throws IOException, JsonParseException, JsonMappingException {
   JsonNode result;
   JsonToken t = _initForReading(jp);
   if (t == JsonToken.VALUE_NULL || t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
     result = NullNode.instance;
   } else {
     DeserializationContext ctxt = _createDeserializationContext(jp, _config);
     JsonDeserializer<Object> deser = _findRootDeserializer(_config, JSON_NODE_TYPE);
     if (_unwrapRoot) {
       result = (JsonNode) _unwrapAndDeserialize(jp, ctxt, JSON_NODE_TYPE, deser);
     } else {
       result = (JsonNode) deser.deserialize(jp, ctxt);
     }
   }
   // Need to consume the token too
   jp.clearCurrentToken();
   return result;
 }