com.fasterxml.jackson.databind.deser.ValueInstantiators Java Examples

The following examples show how to use com.fasterxml.jackson.databind.deser.ValueInstantiators. 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: BQTimeModule.java    From bootique with Apache License 2.0 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
    super.setupModule(context);
    context.addValueInstantiators(new ValueInstantiators.Base() {
        @Override
        public ValueInstantiator findValueInstantiator(DeserializationConfig config,
                                                       BeanDescription beanDesc, ValueInstantiator defaultInstantiator) {
            JavaType type = beanDesc.getType();
            Class<?> raw = type.getRawClass();

            // 15-May-2015, tatu: In theory not safe, but in practice we do need to do "fuzzy" matching
            // because we will (for now) be getting a subtype, but in future may want to downgrade
            // to the common base type. Even more, serializer may purposefully force use of base type.
            // So... in practice it really should always work, in the end. :)
            if (ZoneId.class.isAssignableFrom(raw)) {
                // let's assume we should be getting "empty" StdValueInstantiator here:
                if (defaultInstantiator instanceof StdValueInstantiator) {
                    StdValueInstantiator inst = (StdValueInstantiator) defaultInstantiator;
                    // one further complication: we need ZoneId info, not sub-class
                    AnnotatedClass ac;
                    if (raw == ZoneId.class) {
                        ac = beanDesc.getClassInfo();
                    } else {
                        // we don't need Annotations, so constructing directly is fine here
                        // even if it's not generally recommended
                        ac = AnnotatedClassResolver.resolve(config,
                                config.constructType(ZoneId.class), config);
                    }
                    if (!inst.canCreateFromString()) {
                        AnnotatedMethod factory = _findFactory(ac, "of", String.class);
                        if (factory != null) {
                            inst.configureFromStringCreator(factory);
                        }
                        // otherwise... should we indicate an error?
                    }
                    // return ZoneIdInstantiator.construct(config, beanDesc, defaultInstantiator);
                }
            }
            return defaultInstantiator;
        }
    });
}
 
Example #2
Source File: Module.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method that module can use to register additional {@link com.fasterxml.jackson.databind.deser.ValueInstantiator}s,
 * by adding {@link ValueInstantiators} object that gets called when 
 * instantatiator is needed by a deserializer.
 * 
 * @param instantiators Object that can provide {@link com.fasterxml.jackson.databind.deser.ValueInstantiator}s for
 *    constructing POJO values during deserialization
 */
public void addValueInstantiators(ValueInstantiators instantiators);