com.fitbur.jackson.databind.ext.CoreXMLSerializers Maven / Gradle / Ivy
package com.fitbur.jackson.databind.ext;
import java.io.IOException;
import java.util.Calendar;
import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import com.fitbur.jackson.core.*;
import com.fitbur.jackson.databind.*;
import com.fitbur.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fitbur.jackson.databind.jsontype.TypeSerializer;
import com.fitbur.jackson.databind.ser.ContextualSerializer;
import com.fitbur.jackson.databind.ser.Serializers;
import com.fitbur.jackson.databind.ser.std.CalendarSerializer;
import com.fitbur.jackson.databind.ser.std.StdSerializer;
import com.fitbur.jackson.databind.ser.std.ToStringSerializer;
/**
* Provider for serializers of XML types that are part of full JDK 1.5, but
* that some alleged 1.5 platforms are missing (Android, GAE).
* And for this reason these are added using more dynamic mechanism.
*
* Note: since many of classes defined are abstract, caller must take
* care not to just use straight equivalency check but rather consider
* subclassing as well.
*/
public class CoreXMLSerializers extends Serializers.Base
{
@Override
public JsonSerializer> findSerializer(SerializationConfig config,
JavaType type, BeanDescription beanDesc)
{
Class> raw = type.getRawClass();
if (Duration.class.isAssignableFrom(raw) || QName.class.isAssignableFrom(raw)) {
return ToStringSerializer.instance;
}
if (XMLGregorianCalendar.class.isAssignableFrom(raw)) {
return XMLGregorianCalendarSerializer.instance;
}
return null;
}
@SuppressWarnings("serial")
public static class XMLGregorianCalendarSerializer
extends StdSerializer
implements ContextualSerializer
{
final static XMLGregorianCalendarSerializer instance = new XMLGregorianCalendarSerializer();
final JsonSerializer