Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.deser.std;
  
  
  
Deserializer that builds on basic com.fasterxml.jackson.databind.deser.BeanDeserializer but override some aspects like instance construction.
 
 public class ThrowableDeserializer
     extends BeanDeserializer
 {
     private static final long serialVersionUID = 1L;
 
     protected final static String PROP_NAME_MESSAGE = "message";
 
     /*
     /************************************************************
     /* Construction
     /************************************************************
      */
 
     public ThrowableDeserializer(BeanDeserializer baseDeserializer)
     {
         super(baseDeserializer);
         // need to disable this, since we do post-processing
          = false;
     }

    
Alternative constructor used when creating "unwrapping" deserializers
 
     protected ThrowableDeserializer(BeanDeserializer srcNameTransformer unwrapper)
     {
         super(srcunwrapper);
     }
     
     @Override
     {
         if (getClass() != ThrowableDeserializer.class) {
             return this;
         }
         /* main thing really is to just enforce ignoring of unknown
          * properties; since there may be multiple unwrapped values
          * and properties for all may be interleaved...
          */
         return new ThrowableDeserializer(thisunwrapper);
     }
 
     
     /*
     /************************************************************
     /* Overridden methods
     /************************************************************
      */
 
     @Override
         throws IOExceptionJsonProcessingException
     {
         // 30-Sep-2010, tatu: Need to allow use of @JsonCreator, so:
         if ( != null) { // proper @JsonCreator
             return _deserializeUsingPropertyBased(jpctxt);
         }
         if ( != null) {
             return .createUsingDelegate(ctxt,
                     .deserialize(jpctxt));
         }
         if (.isAbstract()) { // for good measure, check this too
             throw JsonMappingException.from(jp"Can not instantiate abstract type "+
                     +" (need to add/enable type information?)");
         }
         boolean hasStringCreator = .canCreateFromString();
         boolean hasDefaultCtor = .canCreateUsingDefault();
         // and finally, verify we do have single-String arg constructor (if no @JsonCreator)
         if (!hasStringCreator && !hasDefaultCtor) {
             throw new JsonMappingException("Can not deserialize Throwable of type "+
                     +" without having a default contructor, a single-String-arg constructor; or explicit @JsonCreator");
         }
         
         Object throwable = null;
         Object[] pending = null;
         int pendingIx = 0;
 
         for (; jp.getCurrentToken() != .jp.nextToken()) {
             String propName = jp.getCurrentName();
             SettableBeanProperty prop = .find(propName);
             jp.nextToken(); // to point to field value
 
             if (prop != null) { // normal case
                 if (throwable != null) {
                     prop.deserializeAndSet(jpctxtthrowable);
                    continue;
                }
                // nope; need to defer
                if (pending == null) {
                    int len = .size();
                    pending = new Object[len + len];
                }
                pending[pendingIx++] = prop;
                pending[pendingIx++] = prop.deserialize(jpctxt);
                continue;
            }
            // Maybe it's "message"?
            if (.equals(propName)) {
                if (hasStringCreator) {
                    throwable = .createFromString(ctxtjp.getText());
                    // any pending values?
                    if (pending != null) {
                        for (int i = 0, len = pendingIxi < leni += 2) {
                            prop = (SettableBeanProperty)pending[i];
                            prop.set(throwablepending[i+1]);
                        }
                        pending = null;
                    }
                    continue;
                }
            }
            /* As per [JACKSON-313], things marked as ignorable should not be
             * passed to any setter
             */
            if ( != null && .contains(propName)) {
                jp.skipChildren();
                continue;
            }
            if ( != null) {
                .deserializeAndSet(jpctxtthrowablepropName);
                continue;
            }
            // Unknown: let's call handler method
            handleUnknownProperty(jpctxtthrowablepropName);
        }
        // Sanity check: did we find "message"?
        if (throwable == null) {
            /* 15-Oct-2010, tatu: Can't assume missing message is an error, since it may be
             *   suppressed during serialization, as per [JACKSON-388].
             *   
             *   Should probably allow use of default constructor, too...
             */
            //throw new JsonMappingException("No 'message' property found: could not deserialize "+_beanType);
            if (hasStringCreator) {
                throwable = .createFromString(ctxtnull);
            } else {
                throwable = .createUsingDefault(ctxt);
            }
            // any pending values?
            if (pending != null) {
                for (int i = 0, len = pendingIxi < leni += 2) {
                    SettableBeanProperty prop = (SettableBeanProperty)pending[i];
                    prop.set(throwablepending[i+1]);
                }
            }
        }
        return throwable;
    }
New to GrepCode? Check out our FAQ X