TimeZoneSerializer.java
package tools.jackson.databind.ser.jdk;
import java.util.TimeZone;
import tools.jackson.core.*;
import tools.jackson.core.type.WritableTypeId;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.jsontype.TypeSerializer;
import tools.jackson.databind.ser.std.StdScalarSerializer;
public class TimeZoneSerializer extends StdScalarSerializer<TimeZone>
{
public TimeZoneSerializer() { super(TimeZone.class); }
@Override
public void serialize(TimeZone value, JsonGenerator g, SerializationContext provider)
throws JacksonException
{
g.writeString(value.getID());
}
@Override
public void serializeWithType(TimeZone value, JsonGenerator g, SerializationContext ctxt,
TypeSerializer typeSer)
throws JacksonException
{
// Better ensure we don't use specific sub-classes:
WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
typeSer.typeId(value, TimeZone.class, JsonToken.VALUE_STRING));
serialize(value, g, ctxt);
typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
}