Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.datatype.joda.deser;
 
 
 
Basic deserializer for org.joda.time.ReadableDateTime and its subtypes. Accepts JSON String and Number values and passes those to single-argument constructor. Does not (yet?) support JSON object; support can be added if desired.
public class DateTimeDeserializer
    @SuppressWarnings("unchecked")
    public DateTimeDeserializer(Class<? extends ReadableInstantcls) {
        super((Class<ReadableInstant>)cls);
    }
    @SuppressWarnings("unchecked")
    public static <T extends ReadableInstantJsonDeserializer<T> forType(Class<T> cls)
    {
        return (JsonDeserializer<T>) new DateTimeDeserializer(cls);
    }
    
    
    @Override
        throws IOExceptionJsonProcessingException
    {
        JsonToken t = jp.getCurrentToken();
        if (t == .) {
            return new DateTime(jp.getLongValue(), .);
        }
        if (t == .) {
            String str = jp.getText().trim();
            if (str.length() == 0) { // [JACKSON-360]
                return null;
            }
            return new DateTime(str.);
        }
        throw ctxt.mappingException(getValueClass());
    }
New to GrepCode? Check out our FAQ X