Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.module.jaxb.deser;
 
 

Author(s):
Ryan Heaton
Tatu Saloranta
    extends StdDeserializer<Object>
    implements ContextualDeserializer
    protected final XmlAdapter<Object,Object_xmlAdapter;
    protected final JavaType _valueType;
    
    protected final JsonDeserializer<?> _deserializer;

    
Initial constructor, for creating instance before contextual information is available
    @SuppressWarnings("unchecked")
    public XmlAdapterJsonDeserializer(XmlAdapter<?,?> xmlAdapter)
    {
        this((XmlAdapter<Object,Object>) xmlAdapternullnull);
    }

    
Constructor called during contextual resolution, when we have all the pieces we actually need.
    protected  XmlAdapterJsonDeserializer(XmlAdapter<Object,Objectadapter,
            JavaType valueTypeJsonDeserializer<?> deserializer)
    {
        super(Object.class); // type not yet known (will be in a second), but that's ok...
        if (adapter == null) {
            throw new IllegalArgumentException("Null XmlAdapter passed");
        }
         = adapter;
         = valueType;
         = deserializer;
    }
    
            BeanProperty property)
        throws JsonMappingException
    {
        // [JACKSON-404] Need to figure out generic type parameters used...
        TypeFactory typeFactory = ctxt.getTypeFactory();
        JavaType type = typeFactory.constructType(.getClass());
        JavaType[] rawTypes = typeFactory.findTypeParameters(typeXmlAdapter.class);
        JavaType valueType = (rawTypes == null || rawTypes.length == 0)
            ? TypeFactory.unknownType() : rawTypes[0];
        JsonDeserializer<Objectdeser = ctxt.findContextualValueDeserializer(valueTypeproperty);
        return new XmlAdapterJsonDeserializer(valueTypedeser);
    }
    
    @Override
        throws IOExceptionJsonProcessingException
    {
        /* Unfortunately we can not use the usual resolution mechanism (ResolvableDeserializer)
         * because it won't get called due to way adapters are created. So, need to do it
         * lazily when we get here:
         */
        JsonDeserializer<?> deser = ;
        if (deser == null) {
            throw new IllegalStateException("No deserializer assigned for XmlAdapterJsonDeserializer ("
                    +.getClass().getName()+"): resolve() not called?");
        }
        Object boundObject = deser.deserialize(jpctxt);
        try {
            return .unmarshal(boundObject);
        } catch (Exception e) {
            throw new JsonMappingException("Unable to unmarshal (to type "++"): "+e.getMessage(), e);
        }
    }
    @Override
            TypeDeserializer typeDeserializer)
        throws IOExceptionJsonProcessingException
    {
        // Output can be as JSON Object, Array or scalar: no way to know a priori. So:
        return typeDeserializer.deserializeTypedFromAny(jpctxt);
    }
New to GrepCode? Check out our FAQ X