Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.util;
  
  
  
General-purpose wrapper class that can be used to decorate serialized value with arbitrary literal prefix and suffix. This can be used for example to construct arbitrary Javascript values (similar to how basic function name and parenthesis are used with JSONP).

Author(s):
tatu
See also:
JSONPObject
 
 public class JSONWrappedObject
     implements JsonSerializable
 {
    
Literal String to output before serialized value. Will not be quoted when serializing value.
 
     protected final String _prefix;

    
Literal String to output after serialized value. Will not be quoted when serializing value.
 
     protected final String _suffix;
    
    
Value to be serialized as JSONP padded; can be null.
 
     protected final Object _value;

    
Optional static type to use for serialization; if null, runtime type is used. Can be used to specify declared type which defines serializer to use, as well as aspects of extra type information to include (if any).
 
     protected final JavaType _serializationType;
     
     public JSONWrappedObject(String prefixString suffixObject value) {
         this(prefixsuffixvalue, (JavaTypenull);
     }

    
Constructor that should be used when specific serialization type to use is important, and needs to be passed instead of just using runtime (type-erased) type of the value.
 
     public JSONWrappedObject(String prefixString suffixObject valueJavaType asType)
     {
          = prefix;
          = suffix;
          = value;
          = asType;
     }
     
     /*
     /**************************************************************
     /* JsonSerializable(WithType) implementation
     /**************************************************************
      */
     
 //  @Override
     public void serializeWithType(JsonGenerator jgenSerializerProvider providerTypeSerializer typeSer)
             throws IOExceptionJsonProcessingException
     {
         // No type for JSONP wrapping: value serializer will handle typing for value:
         serialize(jgenprovider);
     }
 
 //  @Override
     public void serialize(JsonGenerator jgenSerializerProvider provider)
             throws IOExceptionJsonProcessingException
     {
         // First, wrapping:
     	if ( != nulljgen.writeRaw();
         if ( == null) {
             provider.defaultSerializeNull(jgen);
         } else if ( != null) {
             provider.findTypedValueSerializer(truenull).serialize(jgenprovider);
         } else {
             Class<?> cls = .getClass();
             provider.findTypedValueSerializer(clstruenull).serialize(jgenprovider);
         }
         if ( != nulljgen.writeRaw();
     }
 
     /*
     /**************************************************************
     /* Accessors
     /**************************************************************
     */
    
    public String getPrefix() { return ; }
    public String getSuffix() { return ; }
    public Object getValue() { return ; }
    public JavaType getSerializationType() { return ; }
New to GrepCode? Check out our FAQ X