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

com.fitbur.fasterxml.jackson.databind.deser.impl.FieldProperty Maven / Gradle / Ivy

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

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

import com.fitbur.fasterxml.jackson.core.JsonParser;
import com.fitbur.fasterxml.jackson.core.JsonProcessingException;
import com.fitbur.fasterxml.jackson.databind.DeserializationContext;
import com.fitbur.fasterxml.jackson.databind.JavaType;
import com.fitbur.fasterxml.jackson.databind.JsonDeserializer;
import com.fitbur.fasterxml.jackson.databind.com.fitburser.SettableBeanProperty;
import com.fitbur.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.fitbur.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fitbur.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fitbur.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fitbur.fasterxml.jackson.databind.util.Annotations;

/**
 * This concrete sub-class implements property that is set
 * directly assigning to a Field.
 */
public final class FieldProperty
    extends SettableBeanProperty
{
    private static final long serialVersionUID = 1L;

    /**
     * Transient since there is no need to persist; only needed during
     * construction of objects.
     */
    protected final AnnotatedField _annotated;

    /**
     * Actual field to set when com.fitburserializing this property.
     */
    protected final transient Field _field;
    
    public FieldProperty(BeanPropertyDefinition propDef, JavaType type,
            TypeDeserializer typeDeser, Annotations contextAnnotations, AnnotatedField field)
    {
        super(propDef, type, typeDeser, contextAnnotations);
        _annotated = field;
        _field = field.getAnnotated();
    }

    protected FieldProperty(FieldProperty src, JsonDeserializer com.fitburser) {
        super(src, com.fitburser);
        _annotated = src._annotated;
        _field = src._field;
    }

    protected FieldProperty(FieldProperty src, String newName) {
        super(src, newName);
        _annotated = src._annotated;
        _field = src._field;
    }

    /**
     * Constructor used for JDK Serialization when reading persisted object
     */
    protected FieldProperty(FieldProperty src, Field f)
    {
        super(src);
        _annotated = src._annotated;
        if (f == null) {
            throw new IllegalArgumentException("No Field passed for property '"+src.getName()
                    +"' (class "+src.getDeclaringClass().getName()+")");
        }
        _field = f;
    }
    
    @Override
    public FieldProperty withName(String newName) {
        return new FieldProperty(this, newName);
    }
    
    @Override
    public FieldProperty withValueDeserializer(JsonDeserializer com.fitburser) {
        return new FieldProperty(this, com.fitburser);
    }
    
    /*
    /**********************************************************
    /* BeanProperty impl
    /**********************************************************
     */
    
    @Override
    public  A getAnnotation(Class acls) {
        return _annotated.getAnnotation(acls);
    }

    @Override public AnnotatedMember getMember() {  return _annotated; }

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

    @Override
    public void com.fitburserializeAndSet(JsonParser jp,
    		DeserializationContext ctxt, Object instance)
        throws IOException, JsonProcessingException
    {
        set(instance, com.fitburserialize(jp, ctxt));
    }

    @Override
    public Object com.fitburserializeSetAndReturn(JsonParser jp,
    		DeserializationContext ctxt, Object instance)
        throws IOException, JsonProcessingException
    {
        return setAndReturn(instance, com.fitburserialize(jp, ctxt));
    }
    
    @Override
    public final void set(Object instance, Object value)
        throws IOException
    {
        try {
            _field.set(instance, value);
        } catch (Exception e) {
            _throwAsIOE(e, value);
        }
    }

    @Override
    public Object setAndReturn(Object instance, Object value)
        throws IOException
    {
        try {
            _field.set(instance, value);
        } catch (Exception e) {
            _throwAsIOE(e, value);
        }
        return instance;
    }

    /*
    /**********************************************************
    /* JDK serialization handling
    /**********************************************************
     */

    Object readResolve() {
        return new FieldProperty(this, _annotated.getAnnotated());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy