Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.deser.std;
  
  
Container class for core Jackson type deserializers.
 
 public class JacksonDeserializers
 {
     public static StdDeserializer<?>[] all()
     {
         // note: JsonLocation supported via ValueInstantiator
         return  new StdDeserializer[] {
             new JavaTypeDeserializer(),
             new TokenBufferDeserializer(),
         };
     }
 
             BeanDescription beanDesc)
     {
         if (beanDesc.getBeanClass() == JsonLocation.class) {
             return new JsonLocationInstantiator();
         }
         return null;
     }
     
     /*
     /**********************************************************
     /* Deserializer implementations
     /**********************************************************
      */
    
    
Deserializer for com.fasterxml.jackson.databind.JavaType values.
 
     public static class JavaTypeDeserializer
         extends StdScalarDeserializer<JavaType>
     {
         public JavaTypeDeserializer() { super(JavaType.class); }
         
         @Override
         public JavaType deserialize(JsonParser jpDeserializationContext ctxt)
             throws IOExceptionJsonProcessingException
         {
             JsonToken curr = jp.getCurrentToken();
             // Usually should just get string value:
             if (curr == .) {
                 String str = jp.getText().trim();
                 if (str.length() == 0) {
                     return getEmptyValue();
                 }
                 return ctxt.getTypeFactory().constructFromCanonical(str);
             }
             // or occasionally just embedded object maybe
             if (curr == .) {
                 return (JavaTypejp.getEmbeddedObject();
             }
             throw ctxt.mappingException();
         }
     }

    
For com.fasterxml.jackson.core.JsonLocation, we should be able to just implement com.fasterxml.jackson.databind.deser.ValueInstantiator (not that explicit one would be very hard but...)
 
     public static class JsonLocationInstantiator extends ValueInstantiator
     {
         @Override
         public String getValueTypeDesc() {
             return JsonLocation.class.getName();
         }
         
         @Override
         public boolean canCreateFromObjectWith() { return true; }
         
         @Override
         public CreatorProperty[] getFromObjectArguments(DeserializationConfig config) {
             JavaType intType = config.constructType(.);
             JavaType longType = config.constructType(.);
             return  new CreatorProperty[] {
                     new CreatorProperty("sourceRef"config.constructType(Object.class), nullnullnull, 0, null),
                     new CreatorProperty("byteOffset"longTypenullnullnull, 1, null),
                     new CreatorProperty("charOffset"longTypenullnullnull, 2, null),
                     new CreatorProperty("lineNr"intTypenullnullnull, 3, null),
                    new CreatorProperty("columnNr"intTypenullnullnull, 4, null)
            };
        }
        @Override
        public Object createFromObjectWith(DeserializationContext ctxtObject[] args) {
            return new JsonLocation(args[0], _long(args[1]), _long(args[2]),
                    _int(args[3]), _int(args[4]));
        }
        private final static long _long(Object o) {
            return (o == null) ? 0L : ((Numbero).longValue();
        }
        private final static int _int(Object o) {
            return (o == null) ? 0 : ((Numbero).intValue();
        }
    }
    
    
We also want to directly support deserialization of com.fasterxml.jackson.databind.util.TokenBuffer.

Note that we use scalar deserializer base just because we claim to be of scalar for type information inclusion purposes; actual underlying content can be of any (Object, Array, scalar) type.

    public static class TokenBufferDeserializer
        extends StdScalarDeserializer<TokenBuffer>
    {
        public TokenBufferDeserializer() { super(TokenBuffer.class); }
        @Override
        public TokenBuffer deserialize(JsonParser jpDeserializationContext ctxt)
            throws IOExceptionJsonProcessingException
        {
            TokenBuffer tb = new TokenBuffer(jp.getCodec());
            // quite simple, given that TokenBuffer is a JsonGenerator:
            tb.copyCurrentStructure(jp);
            return tb;
        }
    }
New to GrepCode? Check out our FAQ X