Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.ser.std;
 
 import java.util.Date;
 
 
public class StdKeySerializers
    protected final static JsonSerializer<ObjectDEFAULT_KEY_SERIALIZER = new StdKeySerializer();
    @SuppressWarnings("unchecked")
    protected final static JsonSerializer<ObjectDEFAULT_STRING_SERIALIZER
        = (JsonSerializer<Object>)(JsonSerializer<?>) new StringKeySerializer();
    
    private StdKeySerializers() { }
    @SuppressWarnings("unchecked")
    public static JsonSerializer<ObjectgetStdKeySerializer(JavaType keyType)
    {
        if (keyType == null) {
            return ;
        }
        Class<?> cls = keyType.getRawClass();
        if (cls == String.class) {
            return ;
        }
        if (cls == Object.class) {
            return ;
        }
        // [JACKSON-606] special handling for dates...
        if (Date.class.isAssignableFrom(cls)) {
            return (JsonSerializer<Object>) .;
        }
        if (Calendar.class.isAssignableFrom(cls)) {
            return (JsonSerializer<Object>) .;
        }
        // If no match, just use default one:
        return ;
    }
    /*
    /**********************************************************
    /* Standard implementations
    /**********************************************************
     */
    public static class StringKeySerializer
        extends StdSerializer<String>
    {
        public StringKeySerializer() { super(String.class); }
        
        @Override
        public void serialize(String valueJsonGenerator jgenSerializerProvider provider)
            throws IOExceptionJsonGenerationException
        {
            jgen.writeFieldName(value);
        }
    }
    public static class DateKeySerializer
        extends StdSerializer<Date>
    {
        protected final static JsonSerializer<?> instance = new DateKeySerializer();
        public DateKeySerializer() { super(Date.class); }
        
        @Override
        public void serialize(Date valueJsonGenerator jgenSerializerProvider provider)
            throws IOExceptionJsonGenerationException
        {
            provider.defaultSerializeDateKey(valuejgen);
        }
    }
    public static class CalendarKeySerializer
        extends StdSerializer<Calendar>
    {
        protected final static JsonSerializer<?> instance = new CalendarKeySerializer();
        public CalendarKeySerializer() { super(Calendar.class); }
        
        @Override
        public void serialize(Calendar valueJsonGenerator jgenSerializerProvider provider)
            throws IOExceptionJsonGenerationException
        {
            provider.defaultSerializeDateKey(value.getTimeInMillis(), jgen);
        }
    }
New to GrepCode? Check out our FAQ X