com.fasterxml.jackson.databind.deser.impl.ReadableObjectId Java Examples

The following examples show how to use com.fasterxml.jackson.databind.deser.impl.ReadableObjectId. 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: AbstractDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method called in cases where it looks like we got an Object Id
 * to parse and use as a reference.
 */
protected Object _deserializeFromObjectId(JsonParser p, DeserializationContext ctxt) throws IOException
{
    Object id = _objectIdReader.readObjectReference(p, ctxt);
    ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
    // do we have it resolved?
    Object pojo = roid.resolve();
    if (pojo == null) { // not yet; should wait...
        throw new UnresolvedForwardReference(p,
                "Could not resolve Object Id ["+id+"] -- unresolved forward-reference?", p.getCurrentLocation(), roid);
    }
    return pojo;
}
 
Example #2
Source File: DefaultDeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void checkUnresolvedObjectId() throws UnresolvedForwardReference
{
    if (_objectIds == null) {
        return;
    }
    // 29-Dec-2014, tatu: As per [databind#299], may also just let unresolved refs be...
    if (!isEnabled(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS)) {
        return;
    }
    UnresolvedForwardReference exception = null;
    for (Entry<IdKey,ReadableObjectId> entry : _objectIds.entrySet()) {
        ReadableObjectId roid = entry.getValue();
        if (!roid.hasReferringProperties()) {
            continue;
        }
        // as per [databind#675], allow resolution at this point
        if (tryToResolveUnresolvedObjectId(roid)) {
            continue;
        }
        if (exception == null) {
            exception = new UnresolvedForwardReference(getParser(), "Unresolved forward references for: ");
        }
        Object key = roid.getKey().key;
        for (Iterator<Referring> iterator = roid.referringProperties(); iterator.hasNext(); ) {
            Referring referring = iterator.next();
            exception.addUnresolvedId(key, referring.getBeanType(), referring.getLocation());
        }
    }
    if (exception != null) {
        throw exception;
    }
}
 
Example #3
Source File: UnresolvedForwardReference.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.7
 */
public UnresolvedForwardReference(JsonParser p, String msg, JsonLocation loc, ReadableObjectId roid) {
    super(p, msg, loc);
    _roid = roid;
}
 
Example #4
Source File: UnresolvedForwardReference.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated Since 2.7
 */
@Deprecated // since 2.7
public UnresolvedForwardReference(String msg, JsonLocation loc, ReadableObjectId roid) {
    super(msg, loc);
    _roid = roid;
}
 
Example #5
Source File: UnresolvedForwardReference.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ReadableObjectId getRoid() {
    return _roid;
}
 
Example #6
Source File: Sequence.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public LogicalOperator deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
    JsonProcessingException {
  ObjectIdGenerator<Integer> idGenerator = new ObjectIdGenerators.IntSequenceGenerator();
  JsonLocation start = jp.getCurrentLocation();
  JsonToken t = jp.getCurrentToken();
  LogicalOperator parent = null;
  LogicalOperator first = null;
  LogicalOperator prev = null;
  Integer id = null;

  while (true) {
    String fieldName = jp.getText();
    t = jp.nextToken();
    switch (fieldName) { // switch on field names.
    case "@id":
      id = _parseIntPrimitive(jp, ctxt);
      break;
    case "input":
      JavaType tp = ctxt.constructType(LogicalOperator.class);
      JsonDeserializer<Object> d = ctxt.findRootValueDeserializer(tp);
      parent = (LogicalOperator) d.deserialize(jp, ctxt);
      break;

    case "do":
      if (!jp.isExpectedStartArrayToken()) {
        throwE(
            jp,
            "The do parameter of sequence should be an array of SimpleOperators.  Expected a JsonToken.START_ARRAY token but received a "
                + t.name() + "token.");
      }

      int pos = 0;
      while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
        // logger.debug("Reading sequence child {}.", pos);
        JsonLocation l = jp.getCurrentLocation(); // get current location
                                                  // first so we can
                                                  // correctly reference the
                                                  // start of the object in
                                                  // the case that the type
                                                  // is wrong.
        LogicalOperator o = jp.readValueAs(LogicalOperator.class);

        if (pos == 0) {
          if (!(o instanceof SingleInputOperator) && !(o instanceof SourceOperator)) {
            throwE(
                l,
                "The first operator in a sequence must be either a ZeroInput or SingleInput operator.  The provided first operator was not. It was of type "
                    + o.getClass().getName());
          }
          first = o;
        } else {
          if (!(o instanceof SingleInputOperator)) {
            throwE(l, "All operators after the first must be single input operators.  The operator at position "
                + pos + " was not. It was of type " + o.getClass().getName());
          }
          SingleInputOperator now = (SingleInputOperator) o;
          now.setInput(prev);
        }
        prev = o;

        pos++;
      }
      break;
    default:
      throwE(jp, "Unknown field name provided for Sequence: " + jp.getText());
    }

    t = jp.nextToken();
    if (t == JsonToken.END_OBJECT) {
      break;
    }
  }

  if (first == null) {
    throwE(start, "A sequence must include at least one operator.");
  }
  if ((parent == null && first instanceof SingleInputOperator)
      || (parent != null && first instanceof SourceOperator)) {
    throwE(start,
        "A sequence must either start with a ZeroInputOperator or have a provided input. It cannot have both or neither.");
  }

  if (parent != null && first instanceof SingleInputOperator) {
    ((SingleInputOperator) first).setInput(parent);
  }

  // set input reference.
  if (id != null) {

    ReadableObjectId rid = ctxt.findObjectId(id, idGenerator, null);
    rid.bindItem(prev);
    // logger.debug("Binding id {} to item {}.", rid.id, rid.item);

  }

  return first;
}
 
Example #7
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;
}
 
Example #8
Source File: EntityBeanDeserializer.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) throws IOException {
    if (_nonStandardCreation || _needViewProcesing) {
        return super.deserializeFromObject(p, ctxt);
    }

    Object bean = null;

    if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
        String propertyName = p.getCurrentName();
        do {
            p.nextToken();
            SettableBeanProperty property = _beanProperties.find(propertyName);

            if (property == null) {
                handleUnknownVanilla(p, ctxt, bean, propertyName);
                continue;
            }

            // lazily create the bean, the id property must be the first property
            if (bean == null) {
                if (propertyName.equals(_objectIdReader.propertyName.getSimpleName())) {

                    // deserialize id
                    Object id = property.deserialize(p, ctxt);

                    ReadableObjectId objectId = ctxt.findObjectId(id,
                            _objectIdReader.generator, _objectIdReader.resolver);

                    bean = objectId == null ? null : objectId.resolve();
                    if (bean == null) {
                        bean = _valueInstantiator.createUsingDefault(ctxt);
                        property.set(bean, id);
                    }
                } else {
                    bean = _valueInstantiator.createUsingDefault(ctxt);
                }
                p.setCurrentValue(bean);
            }
            property.deserializeAndSet(p, ctxt, bean);

        } while ((propertyName = p.nextFieldName()) != null);
    }

    return bean;
}
 
Example #9
Source File: DefaultDeserializationContext.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Overridable factory method to create a new instance of ReadableObjectId or its
 * subclass. It is meant to be overridden when custom ReadableObjectId is
 * needed for {@link #tryToResolveUnresolvedObjectId}.
 * Default implementation simply constructs default {@link ReadableObjectId} with
 * given <code>key</code>.
 * 
 * @param key The key to associate with the new ReadableObjectId
 * @return New ReadableObjectId instance
 *
 * @since 2.7
 */
protected ReadableObjectId createReadableObjectId(IdKey key) {
    return new ReadableObjectId(key);
}
 
Example #10
Source File: DefaultDeserializationContext.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Overridable helper method called to try to resolve otherwise unresolvable {@link ReadableObjectId};
 * and if this succeeds, return <code>true</code> to indicate problem has been resolved in
 * some way, so that caller can avoid reporting it as an error.
 *<p>
 * Default implementation simply calls {@link ReadableObjectId#tryToResolveUnresolved} and
 * returns whatever it returns.
 *
 * @since 2.6
 */
protected boolean tryToResolveUnresolvedObjectId(ReadableObjectId roid)
{
    return roid.tryToResolveUnresolved(this);
}
 
Example #11
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method called to find and return entry corresponding to given
 * Object Id: will add an entry if necessary, and never returns null
 */
public abstract ReadableObjectId findObjectId(Object id, ObjectIdGenerator<?> generator, ObjectIdResolver resolver);