Java Code Examples for com.fasterxml.jackson.databind.JsonDeserializer#getObjectIdReader()

The following examples show how to use com.fasterxml.jackson.databind.JsonDeserializer#getObjectIdReader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeserializerModifier.java    From requery with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config,
                                              BeanDescription beanDesc,
                                              JsonDeserializer<?> deserializer) {
    if (deserializer instanceof BeanDeserializer) {
        BeanDeserializer beanDeserializer = (BeanDeserializer) deserializer;
        return new EntityBeanDeserializer(beanDeserializer, deserializer.getObjectIdReader());
    }
    return super.modifyDeserializer(config, beanDesc, deserializer);
}
 
Example 2
Source File: CustomCollectionDeserializer.java    From caravan with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt,
    Object result)
    throws IOException {
  // Ok: must point to START_ARRAY (or equivalent)
  if (!p.isExpectedStartArrayToken()) {
    return handleNonArray(p, ctxt, (Collection<Object>) result);
  }
  // [databind#631]: Assign current value, to be accessible by custom serializers
  p.setCurrentValue(result);

  JsonDeserializer<Object> valueDes = _valueDeserializer;
  final TypeDeserializer typeDeser = _valueTypeDeserializer;
  CollectionReferringAccumulator referringAccumulator =
      (valueDes.getObjectIdReader() == null) ? null :
          new CollectionReferringAccumulator(_containerType.getContentType().getRawClass(), (Collection<Object>) result);

  JsonToken t;
  while ((t = p.nextToken()) != JsonToken.END_ARRAY) {
    try {
      Object value;
      if (t == JsonToken.VALUE_NULL) {
        if (_skipNullValues) {
          continue;
        }
        value = _nullProvider.getNullValue(ctxt);
      } else if (typeDeser == null) {
        value = valueDes.deserialize(p, ctxt);
      } else {
        value = valueDes.deserializeWithType(p, ctxt, typeDeser);
      }
      if (referringAccumulator != null) {
        referringAccumulator.add(value);
      } else {
        ((Collection<Object>) result).add(value);
      }
    } catch (UnresolvedForwardReference reference) {
      if (referringAccumulator == null) {
        throw JsonMappingException
            .from(p, "Unresolved forward reference but no identity info", reference);
      }
      Referring ref = referringAccumulator.handleUnresolvedReference(reference);
      reference.getRoid().appendReferring(ref);
    } catch (Exception e) {
      boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
      if (!wrap) {
        ClassUtil.throwIfRTE(e);
      }
      throw JsonMappingException.wrapWithPath(e, result, ((Collection<Object>) result).size());
    }
  }
  return result;
}
 
Example 3
Source File: ListDeserializer.java    From allure2 with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt,
                                      Collection<Object> result)
        throws IOException {
    // Ok: must point to START_ARRAY (or equivalent)
    if (!p.isExpectedStartArrayToken()) {
        return result;
    }
    // [databind#631]: Assign current value, to be accessible by custom serializers
    p.setCurrentValue(result);

    JsonDeserializer<Object> valueDes = _valueDeserializer;
    final TypeDeserializer typeDeser = _valueTypeDeserializer;
    CollectionReferringAccumulator referringAccumulator =
            (valueDes.getObjectIdReader() == null) ? null :
                    new CollectionReferringAccumulator(_containerType.getContentType().getRawClass(), result);

    JsonToken t;
    while ((t = p.nextToken()) != JsonToken.END_ARRAY) {
        try {
            Object value;
            if (t == JsonToken.VALUE_NULL) {
                if (_skipNullValues) {
                    continue;
                }
                value = _nullProvider.getNullValue(ctxt);
            } else if (typeDeser == null) {
                value = valueDes.deserialize(p, ctxt);
            } else {
                value = valueDes.deserializeWithType(p, ctxt, typeDeser);
            }
            if (referringAccumulator != null) {
                referringAccumulator.add(value);
            } else {
                result.add(value);
            }
        } catch (UnresolvedForwardReference reference) {
            if (referringAccumulator == null) {
                throw JsonMappingException
                        .from(p, "Unresolved forward reference but no identity info", reference);
            }
            ReadableObjectId.Referring ref = referringAccumulator.handleUnresolvedReference(reference);
            reference.getRoid().appendReferring(ref);
        } catch (Exception e) {
            boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
            if (!wrap) {
                ClassUtil.throwIfRTE(e);
            }
            throw JsonMappingException.wrapWithPath(e, result, result.size());
        }
    }
    return result;
}