Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.deser.std;
 
 import java.io.*;
 
 
Base class for simple deserializers that only accept JSON String values as the source.
public abstract class FromStringDeserializer<T>
    extends StdScalarDeserializer<T>
    protected FromStringDeserializer(Class<?> vc) {
        super(vc);
    }
    /*
    /**********************************************************
    /* Deserializer implementations
    /**********************************************************
     */
    
    @SuppressWarnings("unchecked")
    @Override
    public final T deserialize(JsonParser jpDeserializationContext ctxt)
        throws IOExceptionJsonProcessingException
    {
        // 22-Sep-2012, tatu: For 2.1, use this new method, may force coercion:
        String text = jp.getValueAsString();
        if (text != null) { // has String representation
            if (text.length() == 0 || (text = text.trim()).length() == 0) {
                // 15-Oct-2010, tatu: Empty String usually means null, so
                return null;
            }
            try {
                T result = _deserialize(textctxt);
                if (result != null) {
                    return result;
                }
            } catch (IllegalArgumentException iae) {
                // nothing to do here, yet? We'll fail anyway
            }
            throw ctxt.weirdStringException(text"not a valid textual representation");
        }
        if (jp.getCurrentToken() == .) {
            // Trivial cases; null to null, instance of type itself returned as is
            Object ob = jp.getEmbeddedObject();
            if (ob == null) {
                return null;
            }
            if (.isAssignableFrom(ob.getClass())) {
                return (T) ob;
            }
            return _deserializeEmbedded(obctxt);
        }
        throw ctxt.mappingException();
    }
        
    protected abstract T _deserialize(String valueDeserializationContext ctxt)
        throws IOExceptionJsonProcessingException;
    protected T _deserializeEmbedded(Object obDeserializationContext ctxt)
        throws IOExceptionJsonProcessingException
    {
        // default impl: error out
        throw ctxt.mappingException("Don't know how to convert embedded Object of type "
                +ob.getClass().getName()+" into "+.getName());
    }
New to GrepCode? Check out our FAQ X