com.fasterxml.jackson.databind.deser.std.StdDelegatingDeserializer Java Examples

The following examples show how to use com.fasterxml.jackson.databind.deser.std.StdDelegatingDeserializer. 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: JavaUtilCollectionsDeserializers.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static JsonDeserializer<?> findForCollection(DeserializationContext ctxt,
        JavaType type)
    throws JsonMappingException
{
    JavaUtilCollectionsConverter conv;

    // 10-Jan-2017, tatu: Some types from `java.util.Collections`/`java.util.Arrays` need bit of help...
    if (type.hasRawClass(CLASS_AS_ARRAYS_LIST)) {
        conv = converter(TYPE_AS_LIST, type, List.class);
    } else if (type.hasRawClass(CLASS_SINGLETON_LIST)) {
        conv = converter(TYPE_SINGLETON_LIST, type, List.class);
    } else if (type.hasRawClass(CLASS_SINGLETON_SET)) {
        conv = converter(TYPE_SINGLETON_SET, type, Set.class);
    } else if (type.hasRawClass(CLASS_UNMODIFIABLE_LIST)) {
        conv = converter(TYPE_UNMODIFIABLE_LIST, type, List.class);
    } else if (type.hasRawClass(CLASS_UNMODIFIABLE_SET)) {
        conv = converter(TYPE_UNMODIFIABLE_SET, type, Set.class);
    } else {
        return null;
    }
    return new StdDelegatingDeserializer<Object>(conv);
}
 
Example #2
Source File: JavaUtilCollectionsDeserializers.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static JsonDeserializer<?> findForMap(DeserializationContext ctxt,
        JavaType type)
    throws JsonMappingException
{
    JavaUtilCollectionsConverter conv;

    // 10-Jan-2017, tatu: Some types from `java.util.Collections`/`java.util.Arrays` need bit of help...
    if (type.hasRawClass(CLASS_SINGLETON_MAP)) {
        conv = converter(TYPE_SINGLETON_MAP, type, Map.class);
    } else if (type.hasRawClass(CLASS_UNMODIFIABLE_MAP)) {
        conv = converter(TYPE_UNMODIFIABLE_MAP, type, Map.class);
    } else {
        return null;
    }
    return new StdDelegatingDeserializer<Object>(conv);
}
 
Example #3
Source File: BeanDeserializerBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Helper method that can be used to see if specified property is annotated
     * to indicate use of a converter for property value (in case of container types,
     * it is container type itself, not key or content type).
     *<p>
     * NOTE: returned deserializer is NOT yet contextualized, caller needs to take
     * care to do that.
     *
     * @since 2.2
     */
    protected JsonDeserializer<Object> findConvertingDeserializer(DeserializationContext ctxt,
            SettableBeanProperty prop)
        throws JsonMappingException
    {
        final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
        if (intr != null) {
            Object convDef = intr.findDeserializationConverter(prop.getMember());
            if (convDef != null) {
                Converter<Object,Object> conv = ctxt.converterInstance(prop.getMember(), convDef);
                JavaType delegateType = conv.getInputType(ctxt.getTypeFactory());
                // 25-Mar-2017, tatu: should not yet contextualize
//                JsonDeserializer<?> deser = ctxt.findContextualValueDeserializer(delegateType, prop);
                JsonDeserializer<?> deser = ctxt.findNonContextualValueDeserializer(delegateType);
                return new StdDelegatingDeserializer<Object>(conv, delegateType, deser);
            }
        }
        return null;
    }
 
Example #4
Source File: PhysicalPlanReader.java    From Bats with Apache License 2.0 5 votes vote down vote up
public PhysicalPlanReader(DrillConfig config, ScanResult scanResult, LogicalPlanPersistence lpPersistance,
                          final DrillbitEndpoint endpoint, final StoragePluginRegistry pluginRegistry) {

  ObjectMapper lpMapper = lpPersistance.getMapper();

  // Endpoint serializer/deserializer.
  SimpleModule serDeModule = new SimpleModule("PhysicalOperatorModule")
      .addSerializer(DrillbitEndpoint.class, new DrillbitEndpointSerDe.Se())
      .addDeserializer(DrillbitEndpoint.class, new DrillbitEndpointSerDe.De())
      .addSerializer(MajorType.class, new MajorTypeSerDe.Se())
      .addDeserializer(MajorType.class, new MajorTypeSerDe.De())
      .addDeserializer(DynamicPojoRecordReader.class,
          new StdDelegatingDeserializer<>(new DynamicPojoRecordReader.Converter(lpMapper)))
      .addSerializer(Path.class, new PathSerDe.Se());

  lpMapper.registerModule(serDeModule);
  Set<Class<? extends PhysicalOperator>> subTypes = PhysicalOperatorUtil.getSubTypes(scanResult);
  subTypes.forEach(lpMapper::registerSubtypes);
  lpMapper.registerSubtypes(DynamicPojoRecordReader.class);
  InjectableValues injectables = new InjectableValues.Std()
      .addValue(StoragePluginRegistry.class, pluginRegistry)
      .addValue(DrillbitEndpoint.class, endpoint);

  this.mapper = lpMapper;
  this.physicalPlanReader = mapper.readerFor(PhysicalPlan.class).with(injectables);
  this.operatorReader = mapper.readerFor(PhysicalOperator.class).with(injectables);
  this.logicalPlanReader = mapper.readerFor(LogicalPlan.class).with(injectables);
}
 
Example #5
Source File: DeserializerCache.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method that will check whether given annotated entity (usually class,
 * but may also be a property accessor) indicates that a {@link Converter} is to
 * be used; and if so, to construct and return suitable serializer for it.
 * If not, will simply return given serializer as is.
 */
protected JsonDeserializer<Object> findConvertingDeserializer(DeserializationContext ctxt,
        Annotated a, JsonDeserializer<Object> deser)
    throws JsonMappingException
{
    Converter<Object,Object> conv = findConverter(ctxt, a);
    if (conv == null) {
        return deser;
    }
    JavaType delegateType = conv.getInputType(ctxt.getTypeFactory());
    return (JsonDeserializer<Object>) new StdDelegatingDeserializer<Object>(conv, delegateType, deser);
}
 
Example #6
Source File: RangeSetDeserializer.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Override
protected @Nonnull StdDelegatingDeserializer<RangeSet<?>> withDelegate(
    Converter<Object, RangeSet<?>> converter,
    JavaType delegateType,
    JsonDeserializer<?> delegateDeserializer) {
  return new StdDelegatingDeserializer<>(converter, delegateType, delegateDeserializer);
}
 
Example #7
Source File: DeserializerCache.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Method that does the heavy lifting of checking for per-type annotations,
 * find out full type, and figure out which actual factory method
 * to call.
 */
@SuppressWarnings("unchecked")
protected JsonDeserializer<Object> _createDeserializer(DeserializationContext ctxt,
        DeserializerFactory factory, JavaType type)
    throws JsonMappingException
{
    final DeserializationConfig config = ctxt.getConfig();

    // First things first: do we need to use abstract type mapping?
    if (type.isAbstract() || type.isMapLikeType() || type.isCollectionLikeType()) {
        type = factory.mapAbstractType(config, type);
    }
    BeanDescription beanDesc = config.introspect(type);
    // Then: does type define explicit deserializer to use, with annotation(s)?
    JsonDeserializer<Object> deser = findDeserializerFromAnnotation(ctxt,
            beanDesc.getClassInfo());
    if (deser != null) {
        return deser;
    }

    // If not, may have further type-modification annotations to check:
    JavaType newType = modifyTypeByAnnotation(ctxt, beanDesc.getClassInfo(), type);
    if (newType != type) {
        type = newType;
        beanDesc = config.introspect(newType);
    }

    // We may also have a Builder type to consider...
    Class<?> builder = beanDesc.findPOJOBuilder();
    if (builder != null) {
        return (JsonDeserializer<Object>) factory.createBuilderBasedDeserializer(
        		ctxt, type, beanDesc, builder);
    }

    // Or perhaps a Converter?
    Converter<Object,Object> conv = beanDesc.findDeserializationConverter();
    if (conv == null) { // nope, just construct in normal way
        return (JsonDeserializer<Object>) _createDeserializer2(ctxt, factory, type, beanDesc);
    }
    // otherwise need to do bit of introspection
    JavaType delegateType = conv.getInputType(ctxt.getTypeFactory());
    // One more twist, as per [databind#288]; probably need to get new BeanDesc
    if (!delegateType.hasRawClass(type.getRawClass())) {
        beanDesc = config.introspect(delegateType);
    }
    return new StdDelegatingDeserializer<Object>(conv, delegateType,
            _createDeserializer2(ctxt, factory, delegateType, beanDesc));
}