org.codehaus.jackson.map.ser.std.CalendarSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache Show documentation
Show all versions of ehcache Show documentation
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.
package org.codehaus.jackson.map.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Calendar;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.annotate.JacksonStdImpl;
/**
* Standard serializer for {@link java.util.Calendar}.
* As with other time/date types, is configurable to produce timestamps
* (standard Java 64-bit timestamp) or textual formats (usually ISO-8601).
*
* @since 1.9 (moved from 'org.codehaus.jackson.map.ser.StdSerializers#CalendarSerializer}
*/
@JacksonStdImpl
public class CalendarSerializer
extends ScalarSerializerBase
{
public static CalendarSerializer instance = new CalendarSerializer();
public CalendarSerializer() { super(Calendar.class); }
@Override
public void serialize(Calendar value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonGenerationException
{
provider.defaultSerializeDateValue(value.getTimeInMillis(), jgen);
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
//TODO: (ryan) add a format for the date in the schema?
return createSchemaNode(provider.isEnabled(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS)
? "number" : "string", true);
}
}