
eu.interedition.text.json.LayerSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of text-core Show documentation
Show all versions of text-core Show documentation
Stand-off Markup/Annotation Text Model
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