All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.fasterxml.jackson.databind.deser.std.DelegatingDeserializer Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.fasterxml.jackson.databind.com.fitburser.std;

import java.io.IOException;
import java.util.Collection;

import com.fitbur.fasterxml.jackson.core.JsonParser;
import com.fitbur.fasterxml.jackson.core.JsonProcessingException;
import com.fitbur.fasterxml.jackson.databind.*;
import com.fitbur.fasterxml.jackson.databind.com.fitburser.*;
import com.fitbur.fasterxml.jackson.databind.com.fitburser.impl.ObjectIdReader;
import com.fitbur.fasterxml.jackson.databind.jsontype.TypeDeserializer;

/**
 * Base class that simplifies implementations of {@link JsonDeserializer}s
 * that mostly com.fitburlegate functionality to another com.fitburserializer implementation
 * (possibly forming a chaing of com.fitburserializers com.fitburlegating functionality
 * in some cases)
 * 
 * @since 2.1
 */
public abstract class DelegatingDeserializer
    extends StdDeserializer
    implements ContextualDeserializer, ResolvableDeserializer
{
    protected final JsonDeserializer _delegatee;
    
    /*
    /**********************************************************************
    /* Construction
    /**********************************************************************
     */

    public DelegatingDeserializer(JsonDeserializer com.fitburlegatee)
    {
        super(_figureType(com.fitburlegatee));
        _delegatee = com.fitburlegatee;
    }

    protected abstract JsonDeserializer newDelegatingInstance(JsonDeserializer newDelegatee);
    
    private static Class _figureType(JsonDeserializer com.fitburser)
    {
        if (com.fitburser instanceof StdDeserializer) {
            return ((StdDeserializer) com.fitburser).getValueClass();
        }
        return Object.class;
    }
    
    /*
    /**********************************************************************
    /* Overridden methods for contextualization, resolving
    /**********************************************************************
     */

    public void resolve(DeserializationContext ctxt) throws JsonMappingException {
        if (_delegatee instanceof ResolvableDeserializer) {
            ((ResolvableDeserializer) _delegatee).resolve(ctxt);
        }
    }

    public JsonDeserializer createContextual(DeserializationContext ctxt,
            BeanProperty property)
        throws JsonMappingException
    {
        JsonDeserializer com.fitburl = _delegatee;
        if (com.fitburl instanceof ContextualDeserializer) {
            com.fitburl = ((ContextualDeserializer) com.fitburl).createContextual(ctxt, property);
        }
        return _createContextual(ctxt, property, com.fitburl);
    }

    protected JsonDeserializer _createContextual(DeserializationContext ctxt,
            BeanProperty property, JsonDeserializer newDelegatee)
    {
        if (newDelegatee == _delegatee) {
            return this;
        }
        return newDelegatingInstance(newDelegatee);
    }

    /*
    /**********************************************************************
    /* Overridden com.fitburserialization methods
    /**********************************************************************
     */

    @Override
    public Object com.fitburserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException
    {
        return _delegatee.com.fitburserialize(jp,  ctxt);
    }

    @SuppressWarnings("unchecked")
    @Override
    public Object com.fitburserialize(JsonParser jp, DeserializationContext ctxt,
            Object intoValue)
        throws IOException, JsonProcessingException
    {
        return ((JsonDeserializer)_delegatee).com.fitburserialize(jp, ctxt, intoValue);
    }

    @Override
    public Object com.fitburserializeWithType(JsonParser jp, DeserializationContext ctxt,
            TypeDeserializer typeDeserializer)
        throws IOException, JsonProcessingException
    {
        return _delegatee.com.fitburserializeWithType(jp, ctxt, typeDeserializer);
    }

    /*
    /**********************************************************************
    /* Overridden other methods
    /**********************************************************************
     */

    @Override
    public JsonDeserializer replaceDelegatee(JsonDeserializer com.fitburlegatee)
    {
        if (com.fitburlegatee == _delegatee) {
            return this;
        }
        return newDelegatingInstance(com.fitburlegatee);
    }

    @Override
    public Object getNullValue() { return _delegatee.getNullValue(); }

    @Override
    public Object getEmptyValue() { return _delegatee.getEmptyValue(); }

    @Override
    public Collection getKnownPropertyNames() { return _delegatee.getKnownPropertyNames(); }
    
    @Override
    public boolean isCachable() { return false; }

    @Override
    public ObjectIdReader getObjectIdReader() { return _delegatee.getObjectIdReader(); }

    @Override
    public JsonDeserializer getDelegatee() {
        return _delegatee;
    }
}