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

org.codehaus.jackson.map.ser.AnyGetterWriter Maven / Gradle / Ivy

Go to download

Data Mapper package is a high-performance data binding package built on Jackson JSON processor

There is a newer version: 1.9.13
Show newest version
package org.codehaus.jackson.map.ser;

import java.lang.reflect.Method;
import java.util.Map;

import org.codehaus.jackson.*;
import org.codehaus.jackson.map.introspect.AnnotatedMethod;
import org.codehaus.jackson.map.*;

/**
 * Class similar to {@link BeanPropertyWriter}, but that will be used
 * for serializing {@link org.codehaus.jackson.annotate.JsonAnyGetter} annotated
 * (Map) properties
 * 
 * @since 1.6
 */
public class AnyGetterWriter
{
    protected final Method _anyGetter;
    
    protected final MapSerializer _serializer;
    
    public AnyGetterWriter(AnnotatedMethod anyGetter, MapSerializer serializer)
    {
        _anyGetter = anyGetter.getAnnotated();
        _serializer = serializer;
    }

    public void getAndSerialize(Object bean, JsonGenerator jgen, SerializerProvider provider)
        throws Exception
    {
        Object value = _anyGetter.invoke(bean);
        if (value == null) {
            return;
        }
        if (!(value instanceof Map)) {
            throw new JsonMappingException("Value returned by 'any-getter' ("+_anyGetter.getName()+"()) not java.util.Map but "
                    +value.getClass().getName());
        }
        _serializer.serializeFields((Map) value, jgen, provider);
    }

    public void resolve(SerializerProvider provider) throws JsonMappingException
    {
        _serializer.resolve(provider);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy