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

Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.

There is a newer version: 2.10.9.2
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.ser.std.MapSerializer;
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