Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.jsontype.impl;
  
  
  
Type serializer that preferably embeds type information as an additional JSON Object property, if possible (when resulting serialization would use JSON Object). If this is not possible (for JSON Arrays, scalars), uses a JSON Array wrapper (similar to how com.fasterxml.jackson.annotation.JsonTypeInfo.As.WRAPPER_ARRAY always works) as a fallback.

Author(s):
tatus
 
     extends AsArrayTypeSerializer
 {
     protected final String _typePropertyName;
 
     public AsPropertyTypeSerializer(TypeIdResolver idResBeanProperty property,
             String propName)
     {
         super(idResproperty);
          = propName;
     }
 
     @Override
         if ( == propreturn this;
         return new AsPropertyTypeSerializer(this.propthis.);
     }
     
     @Override
     public String getPropertyName() { return ; }
 
     @Override
     public As getTypeInclusion() { return .; }
     
     @Override
     public void writeTypePrefixForObject(Object valueJsonGenerator jgen)
         throws IOExceptionJsonProcessingException
     {
         final String typeId = idFromValue(value);
         if (jgen.canWriteTypeId()) {
             jgen.writeTypeId(typeId);
             jgen.writeStartObject();
         } else {
             jgen.writeStartObject();
             jgen.writeStringField(typeId);
         }
     }
 
     @Override
     public void writeTypePrefixForObject(Object valueJsonGenerator jgenClass<?> type)
         throws IOExceptionJsonProcessingException
     {
         final String typeId = idFromValueAndType(valuetype);
         if (jgen.canWriteTypeId()) {
             jgen.writeTypeId(typeId);
             jgen.writeStartObject();
         } else {
             jgen.writeStartObject();
             jgen.writeStringField(typeId);
         }
     }
     
     //public void writeTypePrefixForArray(Object value, JsonGenerator jgen)
     //public void writeTypePrefixForArray(Object value, JsonGenerator jgen, Class<?> type)
     //public void writeTypePrefixForScalar(Object value, JsonGenerator jgen)
     //public void writeTypePrefixForScalar(Object value, JsonGenerator jgen, Class<?> type)
 
     @Override
     public void writeTypeSuffixForObject(Object valueJsonGenerator jgen)
         throws IOExceptionJsonProcessingException
     {
         // always need to close, regardless of whether its native type id or not
         jgen.writeEndObject();
     }
 
     //public void writeTypeSuffixForArray(Object value, JsonGenerator jgen)
     //public void writeTypeSuffixForScalar(Object value, JsonGenerator jgen)
 
 
     /*
     /**********************************************************
     /* Writing with custom type id
     /**********************************************************
      */
 
     // Only need to override Object-variants
     
     @Override
     public void writeCustomTypePrefixForObject(Object valueJsonGenerator jgenString typeId)
         throws IOExceptionJsonProcessingException
    {
        if (jgen.canWriteTypeId()) {
            jgen.writeTypeId(typeId);
            jgen.writeStartObject();
        } else {
            jgen.writeStartObject();
            jgen.writeStringField(typeId);
        }
    }
    @Override
    public void writeCustomTypeSuffixForObject(Object valueJsonGenerator jgenString typeId)
        throws IOExceptionJsonProcessingException
    {
        jgen.writeEndObject();
    }
New to GrepCode? Check out our FAQ X