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

eu.interedition.text.json.LayerSerializer Maven / Gradle / Ivy

The newest version!
package eu.interedition.text.json;

import eu.interedition.text.Layer;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

/**
 * @author Gregor Middell
 */
class LayerSerializer extends JsonSerializer {

    @Override
    public Class handledType() {
        return Layer.class;
    }

    @Override
    public void serialize(Layer value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
        jgen.writeStartObject();

        jgen.writeObjectField("name", value.getName());
        jgen.writeObjectField("anchors", value.getAnchors());
        jgen.writeObjectField("data", value.data());
        try {
            jgen.writeObjectField("id", value.getClass().getMethod("getId").invoke(value));
        } catch (NoSuchMethodException e) {
        } catch (InvocationTargetException e) {
        } catch (IllegalAccessException e) {
        }

        jgen.writeEndObject();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy