Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.ser.std;
 
 import java.util.*;
 
 
For efficiency, we will serialize Dates as longs, instead of potentially more readable Strings.
public class DateSerializer
    extends DateTimeSerializerBase<Date>
{
    
Default instance that is used when no contextual configuration is needed.
    public static final DateSerializer instance = new DateSerializer();
    
    public DateSerializer() {
        this(falsenull);
    }
        
    public DateSerializer(boolean useTimestampDateFormat customFormat) {
        super(Date.classuseTimestampcustomFormat);
    }
    @Override
    public DateSerializer withFormat(boolean timestampDateFormat customFormat)
    {
        if (timestamp) {
            return new DateSerializer(truenull);
        }
        return new DateSerializer(falsecustomFormat);
    }
    @Override
    protected long _timestamp(Date value) {
        return (value == null) ? 0L : value.getTime();
    }
    @Override
    public void serialize(Date valueJsonGenerator jgenSerializerProvider provider)
        throws IOExceptionJsonGenerationException
    {
        if () {
            jgen.writeNumber(_timestamp(value));
        } else if ( != null) {
            // 21-Feb-2011, tatu: not optimal, but better than alternatives:
            synchronized () {
                jgen.writeString(.format(value));
            }
        } else {
            provider.defaultSerializeDateValue(valuejgen);
        }
    }
New to GrepCode? Check out our FAQ X