private final byte[] handleNonArray(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
 {
   if ((paramJsonParser.getCurrentToken() == JsonToken.VALUE_STRING) && (paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) && (paramJsonParser.getText().length() == 0))
     return null;
   if (!paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY))
     throw paramDeserializationContext.mappingException(this._valueClass);
   JsonToken localJsonToken = paramJsonParser.getCurrentToken();
   if ((localJsonToken == JsonToken.VALUE_NUMBER_INT) || (localJsonToken == JsonToken.VALUE_NUMBER_FLOAT));
   for (int i = paramJsonParser.getByteValue(); ; i = 0)
   {
     return new byte[] { i };
     if (localJsonToken != JsonToken.VALUE_NULL)
       throw paramDeserializationContext.mappingException(this._valueClass.getComponentType());
   }
 }
コード例 #2
0
 @Override
 public JSONObject deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   JSONObject ob = new JSONObject();
   JsonToken t = jp.getCurrentToken();
   if (t == JsonToken.START_OBJECT) {
     t = jp.nextToken();
   }
   for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
     String fieldName = jp.getCurrentName();
     t = jp.nextToken();
     try {
       switch (t) {
         case START_ARRAY:
           ob.put(fieldName, JSONArrayDeserializer.instance.deserialize(jp, ctxt));
           continue;
         case START_OBJECT:
           ob.put(fieldName, deserialize(jp, ctxt));
           continue;
         case VALUE_STRING:
           ob.put(fieldName, jp.getText());
           continue;
         case VALUE_NULL:
           ob.put(fieldName, JSONObject.NULL);
           continue;
         case VALUE_TRUE:
           ob.put(fieldName, Boolean.TRUE);
           continue;
         case VALUE_FALSE:
           ob.put(fieldName, Boolean.FALSE);
           continue;
         case VALUE_NUMBER_INT:
           ob.put(fieldName, jp.getNumberValue());
           continue;
         case VALUE_NUMBER_FLOAT:
           ob.put(fieldName, jp.getNumberValue());
           continue;
         case VALUE_EMBEDDED_OBJECT:
           ob.put(fieldName, jp.getEmbeddedObject());
           continue;
       }
     } catch (JSONException e) {
       throw ctxt.mappingException("Failed to construct JSONObject: " + e.getMessage());
     }
     throw ctxt.mappingException("Urecognized or unsupported JsonToken type: " + t);
   }
   return ob;
 }
コード例 #3
0
 @Override
 public Integer deserialize(JsonParser parser, DeserializationContext context)
     throws IOException {
   JsonToken t = parser.getCurrentToken();
   if (t == JsonToken.VALUE_NUMBER_INT
       || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
     return rangeCheckedInteger(parser, context);
   }
   if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
     String text = parser.getText().trim();
     try {
       int len = text.length();
       if (len > 9) {
         return rangeCheckedInteger(parser, context);
       }
       if (len == 0) {
         return null;
       }
       return Integer.valueOf(NumberInput.parseInt(text));
     } catch (IllegalArgumentException iae) {
       throw context.weirdStringException(_valueClass, "not a valid Integer value"); // NOSONAR
     }
   }
   if (t == JsonToken.VALUE_NULL) {
     return null;
   }
   // Otherwise, no can do:
   throw context.mappingException(_valueClass);
 }
コード例 #4
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.codehaus.jackson.map.JsonDeserializer#deserialize(org.codehaus.jackson
   * .JsonParser, org.codehaus.jackson.map.DeserializationContext)
   */
  @Override
  public NamedErlangFunction deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {

    JsonToken token = jp.getCurrentToken();

    if (JsonToken.START_OBJECT.equals(token)) {

      String mod = null;
      String fun = null;

      while (!JsonToken.END_OBJECT.equals(token)) {
        String field = jp.getCurrentName();

        if (Constants.FL_SCHEMA_FUN_MOD.equals(field)) {
          jp.nextToken();
          mod = jp.getText();
        } else if (Constants.FL_SCHEMA_FUN_FUN.equals(field)) {
          jp.nextToken();
          fun = jp.getText();
        }
        token = jp.nextToken();
      }
      if (mod != null && fun != null) {
        return new NamedErlangFunction(mod, fun);
      } else {
        return null;
      }
    }
    throw ctxt.mappingException(NamedErlangFunction.class);
  }
コード例 #5
0
 @Override
 protected Byte _parseByte(JsonParser jp, DeserializationContext ctxt) throws IOException {
   JsonToken t = jp.getCurrentToken();
   Integer value = null;
   if (t == JsonToken.VALUE_NUMBER_INT
       || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
     value = jp.getIntValue();
   } else if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
     String text = jp.getText().trim();
     try {
       int len = text.length();
       if (len == 0) {
         return getEmptyValue();
       }
       value = NumberInput.parseInt(text);
     } catch (IllegalArgumentException iae) {
       throw ctxt.weirdStringException(_valueClass, "not a valid Byte value"); // NOSONAR
     }
   }
   if (value != null) {
     // So far so good: but does it fit?
     if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
       throw ctxt.weirdStringException(
           _valueClass, "overflow, value can not be represented as 8-bit value");
     }
     return (byte) (int) value;
   }
   if (t == JsonToken.VALUE_NULL) {
     return getNullValue();
   }
   throw ctxt.mappingException(_valueClass, t);
 }
コード例 #6
0
 protected T _deserializeEmbedded(
     Object paramObject, DeserializationContext paramDeserializationContext) throws IOException {
   throw paramDeserializationContext.mappingException(
       "Don't know how to convert embedded Object of type "
           + paramObject.getClass().getName()
           + " into "
           + this._valueClass.getName());
 }
 private final boolean[] handleNonArray(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
 {
   if ((paramJsonParser.getCurrentToken() == JsonToken.VALUE_STRING) && (paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) && (paramJsonParser.getText().length() == 0))
     return null;
   if (!paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY))
     throw paramDeserializationContext.mappingException(this._valueClass);
   boolean[] arrayOfBoolean = new boolean[1];
   arrayOfBoolean[0] = _parseBooleanPrimitive(paramJsonParser, paramDeserializationContext);
   return arrayOfBoolean;
 }
 public char[] deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
 {
   JsonToken localJsonToken1 = paramJsonParser.getCurrentToken();
   if (localJsonToken1 == JsonToken.VALUE_STRING)
   {
     char[] arrayOfChar1 = paramJsonParser.getTextCharacters();
     int i = paramJsonParser.getTextOffset();
     int j = paramJsonParser.getTextLength();
     char[] arrayOfChar2 = new char[j];
     System.arraycopy(arrayOfChar1, i, arrayOfChar2, 0, j);
     return arrayOfChar2;
   }
   if (paramJsonParser.isExpectedStartArrayToken())
   {
     StringBuilder localStringBuilder = new StringBuilder(64);
     while (true)
     {
       JsonToken localJsonToken2 = paramJsonParser.nextToken();
       if (localJsonToken2 == JsonToken.END_ARRAY)
         break;
       if (localJsonToken2 != JsonToken.VALUE_STRING)
         throw paramDeserializationContext.mappingException(Character.TYPE);
       String str = paramJsonParser.getText();
       if (str.length() != 1)
         throw JsonMappingException.from(paramJsonParser, "Can not convert a JSON String of length " + str.length() + " into a char element of char array");
       localStringBuilder.append(str.charAt(0));
     }
     return localStringBuilder.toString().toCharArray();
   }
   if (localJsonToken1 == JsonToken.VALUE_EMBEDDED_OBJECT)
   {
     Object localObject = paramJsonParser.getEmbeddedObject();
     if (localObject == null)
       return null;
     if ((localObject instanceof char[]))
       return (char[])localObject;
     if ((localObject instanceof String))
       return ((String)localObject).toCharArray();
     if ((localObject instanceof byte[]))
       return Base64Variants.getDefaultVariant().encode((byte[])localObject, false).toCharArray();
   }
   throw paramDeserializationContext.mappingException(this._valueClass);
 }
コード例 #9
0
  @Override
  public String deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {
    if (jp.hasCurrentToken() && jp.getCurrentToken().equals(JsonToken.START_OBJECT)) {
      ObjectMapper mapper = new ObjectMapper();
      JsonNode node = mapper.reader(JsonNode.class).readValue(jp);
      return node.has(VALUE) ? node.get(VALUE).textValue() : null;
    }

    throw ctxt.mappingException("Expected JSON object");
  }
コード例 #10
0
 @Override
 public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
   JsonToken t = jp.getCurrentToken();
   if (t == JsonToken.VALUE_STRING) {
     String str = jp.getText().trim();
     return ISODateTimeFormat.dateTimeParser().parseDateTime(str).toLocalDate();
   }
   if (t == JsonToken.VALUE_NUMBER_INT) {
     return new LocalDate(jp.getLongValue());
   }
   throw ctxt.mappingException(handledType());
 }
コード例 #11
0
  @Override
  public Enum<?> deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {
    JsonToken curr = jp.getCurrentToken();

    // Usually should just get string value:
    if (curr == JsonToken.VALUE_STRING || curr == JsonToken.FIELD_NAME) {
      String name = jp.getText();
      Enum<?> result = _resolver.findEnum(name);
      if (result == null
          && !ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
        throw ctxt.weirdStringException(
            name, _resolver.getEnumClass(), "value not one of declared Enum instance names");
      }
      return result;
    }
    // But let's consider int acceptable as well (if within ordinal range)
    if (curr == JsonToken.VALUE_NUMBER_INT) {
      /* ... unless told not to do that. :-)
       * (as per [JACKSON-412]
       */
      if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS)) {
        throw ctxt.mappingException(
            "Not allowed to deserialize Enum value out of JSON number (disable DeserializationConfig.DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS to allow)");
      }

      int index = jp.getIntValue();
      Enum<?> result = _resolver.getEnum(index);
      if (result == null
          && !ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
        throw ctxt.weirdNumberException(
            Integer.valueOf(index),
            _resolver.getEnumClass(),
            "index value outside legal index range [0.." + _resolver.lastValidIndex() + "]");
      }
      return result;
    }
    throw ctxt.mappingException(_resolver.getEnumClass());
  }
 public ObjectNode deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext)
 {
     if (jsonparser.getCurrentToken() == JsonToken.START_OBJECT)
     {
         jsonparser.nextToken();
         return deserializeObject(jsonparser, deserializationcontext, deserializationcontext.getNodeFactory());
     }
     if (jsonparser.getCurrentToken() == JsonToken.FIELD_NAME)
     {
         return deserializeObject(jsonparser, deserializationcontext, deserializationcontext.getNodeFactory());
     } else
     {
         throw deserializationcontext.mappingException(com/fasterxml/jackson/databind/node/ObjectNode);
     }
 }
コード例 #13
0
 @Override
 public Long deserialize(JsonParser parser, DeserializationContext context) throws IOException {
   JsonToken t = parser.getCurrentToken();
   // it should be ok to coerce (although may fail, too)
   if (t == JsonToken.VALUE_NUMBER_INT
       || t == JsonToken.VALUE_NUMBER_FLOAT
       || t == JsonToken.VALUE_STRING) {
     return rangeCheckedLong(parser, context);
   }
   if (t == JsonToken.VALUE_NULL) {
     return null;
   }
   // Otherwise, no can do:
   throw context.mappingException(_valueClass);
 }
コード例 #14
0
 @Override
 public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
   JsonToken t = jp.getCurrentToken();
   if (t == JsonToken.VALUE_STRING) {
     String str = jp.getText().trim();
     try {
       Date date = new SimpleDateFormat(PATTERN).parse(str);
       return new DateTime(date);
     } catch (ParseException e) {
       throw new RuntimeException(e);
     }
   }
   if (t == JsonToken.VALUE_NUMBER_INT) {
     return new DateTime(jp.getLongValue());
   }
   throw ctxt.mappingException(handledType());
 }
 public byte[] deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
 {
   JsonToken localJsonToken1 = paramJsonParser.getCurrentToken();
   if (localJsonToken1 == JsonToken.VALUE_STRING)
     return paramJsonParser.getBinaryValue(paramDeserializationContext.getBase64Variant());
   if (localJsonToken1 == JsonToken.VALUE_EMBEDDED_OBJECT)
   {
     Object localObject2 = paramJsonParser.getEmbeddedObject();
     if (localObject2 == null)
       return null;
     if ((localObject2 instanceof byte[]))
       return (byte[])localObject2;
   }
   if (!paramJsonParser.isExpectedStartArrayToken())
     return handleNonArray(paramJsonParser, paramDeserializationContext);
   ArrayBuilders.ByteBuilder localByteBuilder = paramDeserializationContext.getArrayBuilders().getByteBuilder();
   Object localObject1 = (byte[])localByteBuilder.resetAndStart();
   int i = 0;
   JsonToken localJsonToken2 = paramJsonParser.nextToken();
   int j;
   label130: int k;
   if (localJsonToken2 != JsonToken.END_ARRAY)
     if ((localJsonToken2 == JsonToken.VALUE_NUMBER_INT) || (localJsonToken2 == JsonToken.VALUE_NUMBER_FLOAT))
     {
       j = paramJsonParser.getByteValue();
       if (i < localObject1.length)
         break label214;
       byte[] arrayOfByte = (byte[])localByteBuilder.appendCompletedChunk(localObject1, i);
       k = 0;
       localObject1 = arrayOfByte;
     }
   while (true)
   {
     i = k + 1;
     localObject1[k] = j;
     break;
     if (localJsonToken2 != JsonToken.VALUE_NULL)
       throw paramDeserializationContext.mappingException(this._valueClass.getComponentType());
     j = 0;
     break label130;
     return (byte[])localByteBuilder.completeAndClearBuffer(localObject1, i);
     label214: k = i;
   }
 }
コード例 #16
0
  @Override
  public JsonObject deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonObjectBuilder builder = JsonObjectBuilder.object();

    JsonToken t = jp.getCurrentToken();
    if (t == JsonToken.START_OBJECT) {
      t = jp.nextToken();
    }
    for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
      String fieldName = jp.getCurrentName();
      t = jp.nextToken();

      switch (t) {
        case START_ARRAY:
          builder.put(fieldName, JsonArrayDeserializer.INSTANCE.deserialize(jp, ctxt));
          continue;
        case START_OBJECT:
          builder.put(fieldName, deserialize(jp, ctxt));
          continue;
        case VALUE_STRING:
          builder.put(fieldName, jp.getText());
          continue;
        case VALUE_NULL:
          builder.putNull(fieldName);
          continue;
        case VALUE_TRUE:
          builder.put(fieldName, Boolean.TRUE);
          continue;
        case VALUE_FALSE:
          builder.put(fieldName, Boolean.FALSE);
          continue;
        case VALUE_NUMBER_INT:
          builder.put(fieldName, jp.getNumberValue());
          continue;
        case VALUE_NUMBER_FLOAT:
          builder.put(fieldName, jp.getNumberValue());
          continue;
        default:
          throw ctxt.mappingException("Unrecognized or unsupported JsonToken type: " + t);
      }
    }

    return builder.build();
  }
コード例 #17
0
  /**
   * Helper method called when current token is no START_ARRAY. Will either throw an exception, or
   * try to handle value as if member of implicit array, depending on configuration.
   */
  private final Collection<String> handleNonArray(
      JsonParser jp, DeserializationContext ctxt, Collection<String> result) throws IOException {
    // [JACKSON-526]: implicit arrays from single values?
    if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
      throw ctxt.mappingException(_collectionType.getRawClass());
    }
    // Strings are one of "native" (intrinsic) types, so there's never type deserializer involved
    JsonDeserializer<String> valueDes = _valueDeserializer;
    JsonToken t = jp.getCurrentToken();

    String value;

    if (t == JsonToken.VALUE_NULL) {
      value = (valueDes == null) ? null : valueDes.getNullValue();
    } else {
      value = (valueDes == null) ? _parseString(jp, ctxt) : valueDes.deserialize(jp, ctxt);
    }
    result.add(value);
    return result;
  }
 private final String[] handleNonArray(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
 {
   if (!paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY))
   {
     if ((paramJsonParser.getCurrentToken() == JsonToken.VALUE_STRING) && (paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) && (paramJsonParser.getText().length() == 0))
       return null;
     throw paramDeserializationContext.mappingException(this._valueClass);
   }
   String[] arrayOfString = new String[1];
   JsonToken localJsonToken1 = paramJsonParser.getCurrentToken();
   JsonToken localJsonToken2 = JsonToken.VALUE_NULL;
   String str = null;
   if (localJsonToken1 == localJsonToken2);
   while (true)
   {
     arrayOfString[0] = str;
     return arrayOfString;
     str = _parseString(paramJsonParser, paramDeserializationContext);
   }
 }
コード例 #19
0
 @Override
 public Object deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   // couple of accepted types...
   Object value;
   if (_inputType == null) {
     value = jp.getText();
   } else if (_inputType == Integer.class) {
     value = Integer.valueOf(jp.getValueAsInt());
   } else if (_inputType == Long.class) {
     value = Long.valueOf(jp.getValueAsLong());
   } else {
     throw ctxt.mappingException(_enumClass);
   }
   try {
     return _factory.invoke(_enumClass, value);
   } catch (Exception e) {
     ClassUtil.unwrapAndThrowAsIAE(e);
   }
   return null;
 }
コード例 #20
0
 @Override
 public JSONArray deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   JSONArray array = new JSONArray();
   JsonToken t;
   while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
     switch (t) {
       case START_ARRAY:
         array.put(deserialize(jp, ctxt));
         continue;
       case START_OBJECT:
         array.put(JSONObjectDeserializer.instance.deserialize(jp, ctxt));
         continue;
       case VALUE_STRING:
         array.put(jp.getText());
         continue;
       case VALUE_NULL:
         array.put(JSONObject.NULL);
         continue;
       case VALUE_TRUE:
         array.put(Boolean.TRUE);
         continue;
       case VALUE_FALSE:
         array.put(Boolean.FALSE);
         continue;
       case VALUE_NUMBER_INT:
         array.put(jp.getNumberValue());
         continue;
       case VALUE_NUMBER_FLOAT:
         array.put(jp.getNumberValue());
         continue;
       case VALUE_EMBEDDED_OBJECT:
         array.put(jp.getEmbeddedObject());
         continue;
     }
     throw ctxt.mappingException("Urecognized or unsupported JsonToken type: " + t);
   }
   return array;
 }
コード例 #21
0
 /* (non-Javadoc)
  * @see org.codehaus.jackson.map.JsonDeserializer#deserialize(org.codehaus.jackson.JsonParser, org.codehaus.jackson.map.DeserializationContext)
  */
 @Override
 public Quorum deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   JsonToken token = jp.getCurrentToken();
   switch (token) {
     case VALUE_STRING:
       {
         return new Quorum(Quora.fromString(jp.getText()));
       }
     case VALUE_NUMBER_INT:
       {
         return new Quorum(jp.getIntValue());
       }
     case VALUE_NULL:
       {
         return null;
       }
     default:
       break;
   }
   throw ctxt.mappingException(Quorum.class);
 }
コード例 #22
0
 @Override
 public String deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   // 22-Sep-2012, tatu: For 2.1, use this new method, may force coercion:
   String text = jp.getValueAsString();
   if (text != null) {
     return text;
   }
   // [JACKSON-330]: need to gracefully handle byte[] data, as base64
   JsonToken curr = jp.getCurrentToken();
   if (curr == JsonToken.VALUE_EMBEDDED_OBJECT) {
     Object ob = jp.getEmbeddedObject();
     if (ob == null) {
       return null;
     }
     if (ob instanceof byte[]) {
       return Base64Variants.getDefaultVariant().encode((byte[]) ob, false);
     }
     // otherwise, try conversion using toString()...
     return ob.toString();
   }
   throw ctxt.mappingException(_valueClass, curr);
 }
コード例 #23
0
 public T deserialize(
     JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
     throws IOException {
   Object localObject;
   String str;
   if ((paramJsonParser.getCurrentToken() == JsonToken.START_ARRAY)
       && (paramDeserializationContext.isEnabled(
           DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS))) {
     paramJsonParser.nextToken();
     localObject = deserialize(paramJsonParser, paramDeserializationContext);
     if (paramJsonParser.nextToken() != JsonToken.END_ARRAY) {
       throw paramDeserializationContext.wrongTokenException(
           paramJsonParser,
           JsonToken.END_ARRAY,
           "Attempted to unwrap single value array for single '"
               + this._valueClass.getName()
               + "' value but there was more than a single value in the array");
     }
   } else {
     localObject = paramJsonParser.getValueAsString();
     if (localObject == null) {
       break label194;
     }
     if (((String) localObject).length() != 0) {
       str = ((String) localObject).trim();
       if (str.length() != 0) {
         break label118;
       }
     }
     localObject = _deserializeFromEmptyString();
   }
   return (T) localObject;
   label118:
   paramJsonParser = null;
   try {
     localObject = _deserialize(str, paramDeserializationContext);
     if (localObject != null) {
       return (T) localObject;
     }
   } catch (IllegalArgumentException paramJsonParser) {
     localObject = "not a valid textual representation";
     if (paramJsonParser != null) {
       localObject =
           "not a valid textual representation" + "problem: " + paramJsonParser.getMessage();
     }
     paramDeserializationContext =
         paramDeserializationContext.weirdStringException(
             str, this._valueClass, (String) localObject);
     if (paramJsonParser != null) {
       paramDeserializationContext.initCause(paramJsonParser);
     }
     throw paramDeserializationContext;
   }
   label194:
   if (paramJsonParser.getCurrentToken() == JsonToken.VALUE_EMBEDDED_OBJECT) {
     paramJsonParser = paramJsonParser.getEmbeddedObject();
     if (paramJsonParser == null) {
       return null;
     }
     if (this._valueClass.isAssignableFrom(paramJsonParser.getClass())) {
       return paramJsonParser;
     }
     return (T) _deserializeEmbedded(paramJsonParser, paramDeserializationContext);
   }
   throw paramDeserializationContext.mappingException(this._valueClass);
 }
コード例 #24
0
  /**
   * Method called to figure out settable properties for the bean deserializer to use.
   *
   * <p>Note: designed to be overridable, and effort is made to keep interface similar between
   * versions.
   */
  protected void addBeanProps(
      DeserializationContext ctxt, BeanDescription beanDesc, BeanDeserializerBuilder builder)
      throws JsonMappingException {
    final SettableBeanProperty[] creatorProps =
        builder.getValueInstantiator().getFromObjectArguments(ctxt.getConfig());

    // Things specified as "ok to ignore"? [JACKSON-77]
    AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
    boolean ignoreAny = false;
    {
      Boolean B = intr.findIgnoreUnknownProperties(beanDesc.getClassInfo());
      if (B != null) {
        ignoreAny = B.booleanValue();
        builder.setIgnoreUnknownProperties(ignoreAny);
      }
    }
    // Or explicit/implicit definitions?
    Set<String> ignored =
        ArrayBuilders.arrayToSet(intr.findPropertiesToIgnore(beanDesc.getClassInfo()));
    for (String propName : ignored) {
      builder.addIgnorable(propName);
    }
    // Also, do we have a fallback "any" setter?
    AnnotatedMethod anySetter = beanDesc.findAnySetter();
    if (anySetter != null) {
      builder.setAnySetter(constructAnySetter(ctxt, beanDesc, anySetter));
    }
    // NOTE: we do NOT add @JsonIgnore'd properties into blocked ones if there's any setter
    // Implicit ones via @JsonIgnore and equivalent?
    if (anySetter == null) {
      Collection<String> ignored2 = beanDesc.getIgnoredPropertyNames();
      if (ignored2 != null) {
        for (String propName : ignored2) {
          // allow ignoral of similarly named JSON property, but do not force;
          // latter means NOT adding this to 'ignored':
          builder.addIgnorable(propName);
        }
      }
    }
    final boolean useGettersAsSetters =
        (ctxt.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS)
            && ctxt.isEnabled(MapperFeature.AUTO_DETECT_GETTERS));

    // Ok: let's then filter out property definitions
    List<BeanPropertyDefinition> propDefs =
        filterBeanProps(ctxt, beanDesc, builder, beanDesc.findProperties(), ignored);

    // After which we can let custom code change the set
    if (_factoryConfig.hasDeserializerModifiers()) {
      for (BeanDeserializerModifier mod : _factoryConfig.deserializerModifiers()) {
        propDefs = mod.updateProperties(ctxt.getConfig(), beanDesc, propDefs);
      }
    }

    // At which point we still have all kinds of properties; not all with mutators:
    for (BeanPropertyDefinition propDef : propDefs) {
      SettableBeanProperty prop = null;
      if (propDef.hasConstructorParameter()) {
        /* [JACKSON-700] If property is passed via constructor parameter, we must
         *   handle things in special way. Not sure what is the most optimal way...
         *   for now, let's just call a (new) method in builder, which does nothing.
         */
        // but let's call a method just to allow custom builders to be aware...
        final String name = propDef.getName();
        for (SettableBeanProperty cp : creatorProps) {
          if (name.equals(cp.getName())) {
            prop = cp;
            break;
          }
        }
        if (prop == null) {
          throw ctxt.mappingException("Could not find creator property with name '" + name + "'");
        }
        builder.addCreatorProperty(prop);
        continue;
      }
      if (propDef.hasSetter()) {
        Type propertyType = propDef.getSetter().getGenericParameterType(0);
        prop = constructSettableProperty(ctxt, beanDesc, propDef, propertyType);
      } else if (propDef.hasField()) {
        Type propertyType = propDef.getField().getGenericType();
        prop = constructSettableProperty(ctxt, beanDesc, propDef, propertyType);
      } else if (useGettersAsSetters && propDef.hasGetter()) {
        /* As per [JACKSON-88], may also need to consider getters
         * for Map/Collection properties; but with lowest precedence
         */
        AnnotatedMethod getter = propDef.getGetter();
        // should only consider Collections and Maps, for now?
        Class<?> rawPropertyType = getter.getRawType();
        if (Collection.class.isAssignableFrom(rawPropertyType)
            || Map.class.isAssignableFrom(rawPropertyType)) {
          prop = constructSetterlessProperty(ctxt, beanDesc, propDef);
        }
      }
      if (prop != null) {
        Class<?>[] views = propDef.findViews();
        if (views == null) {
          // one more twist: if default inclusion disabled, need to force empty set of views
          if (!ctxt.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)) {
            views = NO_VIEWS;
          }
        }
        // one more thing before adding to builder: copy any metadata
        prop.setViews(views);
        builder.addProperty(prop);
      }
    }
  }