com.fasterxml.jackson.annotation.ObjectIdResolver Java Examples

The following examples show how to use com.fasterxml.jackson.annotation.ObjectIdResolver. 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: SpringHandlerInstantiator.java    From java-technology-stack with MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public ObjectIdResolver resolverIdGeneratorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ObjectIdResolver) this.beanFactory.createBean(implClass);
}
 
Example #2
Source File: SpringHandlerInstantiator.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public ObjectIdResolver resolverIdGeneratorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ObjectIdResolver) this.beanFactory.createBean(implClass);
}
 
Example #3
Source File: ResolverInstantiator.java    From requery with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectIdResolver resolverIdGeneratorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
    if (implClass.isAssignableFrom(EntityStoreResolver.class)) {
        return new EntityStoreResolver(store);
    }
    return null;
}
 
Example #4
Source File: ObjectIdInfo.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ObjectIdInfo(PropertyName prop, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen,
        boolean alwaysAsId, Class<? extends ObjectIdResolver> resolver)
{
    _propertyName = prop;
    _scope = scope;
    _generator = gen;
    _alwaysAsId = alwaysAsId;
    if (resolver == null) {
        resolver = SimpleObjectIdResolver.class;
    }
    _resolver = resolver;
}
 
Example #5
Source File: ObjectIdReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Factory method called by {@link com.fasterxml.jackson.databind.ser.std.BeanSerializerBase}
 * with the initial information based on standard settings for the type
 * for which serializer is being built.
 */
public static ObjectIdReader construct(JavaType idType, PropertyName propName,
        ObjectIdGenerator<?> generator, JsonDeserializer<?> deser,
        SettableBeanProperty idProp, ObjectIdResolver resolver)
{
    return new ObjectIdReader(idType, propName, generator, deser, idProp, resolver);
}
 
Example #6
Source File: ObjectIdReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected ObjectIdReader(JavaType t, PropertyName propName, ObjectIdGenerator<?> gen,
        JsonDeserializer<?> deser, SettableBeanProperty idProp, ObjectIdResolver resolver)
{
    _idType = t;
    propertyName = propName;
    generator = gen;
    this.resolver = resolver;
    _deserializer = (JsonDeserializer<Object>) deser;
    idProperty = idProp;
}
 
Example #7
Source File: ByIdProperty.java    From immutables with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectIdResolver newForDeserialization(Object context) {
  return new ByidInstanceResolver();
}
 
Example #8
Source File: EntityStoreResolver.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canUseFor(ObjectIdResolver resolverType) {
    return false;
}
 
Example #9
Source File: EntityStoreResolver.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectIdResolver newForDeserialization(Object context) {
    return this;
}
 
Example #10
Source File: ReadableObjectId.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setResolver(ObjectIdResolver resolver) {
    _resolver = resolver;
}
 
Example #11
Source File: AbstractDeserializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
    public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
            BeanProperty property) throws JsonMappingException
    {
        final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
        if (property != null && intr != null) {
            final AnnotatedMember accessor = property.getMember();
            if (accessor != null) {
                ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor);
                if (objectIdInfo != null) { // some code duplication here as well (from BeanDeserializerFactory)
                    JavaType idType;
                    ObjectIdGenerator<?> idGen;
                    SettableBeanProperty idProp = null;
                    ObjectIdResolver resolver = ctxt.objectIdResolverInstance(accessor, objectIdInfo);

                    // 2.1: allow modifications by "id ref" annotations as well:
                    objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo);
                    Class<?> implClass = objectIdInfo.getGeneratorType();

                    if (implClass == ObjectIdGenerators.PropertyGenerator.class) {
                        PropertyName propName = objectIdInfo.getPropertyName();
                        idProp = (_properties == null) ? null : _properties.get(propName.getSimpleName());
                        if (idProp == null) {
                            ctxt.reportBadDefinition(_baseType, String.format(
                                    "Invalid Object Id definition for %s: cannot find property with name '%s'",
                                    handledType().getName(), propName));
                        }
                        idType = idProp.getType();
                        idGen = new PropertyBasedObjectIdGenerator(objectIdInfo.getScope());
/*
                         ctxt.reportBadDefinition(_baseType, String.format(
/
"Invalid Object Id definition for abstract type %s: cannot use `PropertyGenerator` on polymorphic types using property annotation",
handledType().getName()));
*/
                    } else { // other types simpler
                        resolver = ctxt.objectIdResolverInstance(accessor, objectIdInfo);
                        JavaType type = ctxt.constructType(implClass);
                        idType = ctxt.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0];
                        idGen = ctxt.objectIdGeneratorInstance(accessor, objectIdInfo);
                    }
                    JsonDeserializer<?> deser = ctxt.findRootValueDeserializer(idType);
                    ObjectIdReader oir = ObjectIdReader.construct(idType, objectIdInfo.getPropertyName(),
                             idGen, deser, idProp, resolver);
                    return new AbstractDeserializer(this, oir, null);
                }
            }
        }
        if (_properties == null) {
            return this;
        }
        // Need to ensure properties are dropped at this point, regardless
        return new AbstractDeserializer(this, _objectIdReader, null);
    }
 
Example #12
Source File: ObjectIdInfo.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ObjectIdInfo(PropertyName name, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen,
        Class<? extends ObjectIdResolver> resolver)
{
    this(name, scope, gen, false, resolver);
}
 
Example #13
Source File: HandlerInstantiator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ObjectIdResolver resolverIdGeneratorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
    return null;
}
 
Example #14
Source File: SpringHandlerInstantiator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** @since 4.3 */
@Override
public ObjectIdResolver resolverIdGeneratorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
	return (ObjectIdResolver) this.beanFactory.createBean(implClass);
}
 
Example #15
Source File: ReadableObjectId.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Allow access to the resolver in case anybody wants to use it directly, for
 * examples from 
 * {@link com.fasterxml.jackson.databind.deser.DefaultDeserializationContext#tryToResolveUnresolvedObjectId}.
 *
 * @return The registered resolver
 * 
 * @since 2.7
 */
public ObjectIdResolver getResolver() {
    return _resolver;
}
 
Example #16
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);
 
Example #17
Source File: ObjectIdInfo.java    From lams with GNU General Public License v2.0 votes vote down vote up
public Class<? extends ObjectIdResolver> getResolverType() { return _resolver; }