Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.jsontype.impl;
  
  
  
Type serializer that will embed type information in an array, as the first element, and actual value as the second element.

Author(s):
tatu
 
 public class AsArrayTypeSerializer
     extends TypeSerializerBase
 {
     public AsArrayTypeSerializer(TypeIdResolver idResBeanProperty property)
     {
         super(idResproperty);
     }
 
     @Override
     public AsArrayTypeSerializer forProperty(BeanProperty prop) {
         if ( == propreturn this;
         return new AsArrayTypeSerializer(this.prop);
     }
     
     @Override
     public As getTypeInclusion() { return .; }
     
     /*
     /**********************************************************
     /* Writing prefixes
     /**********************************************************
      */
     
     @Override
     public void writeTypePrefixForObject(Object valueJsonGenerator jgen)
         throws IOExceptionJsonProcessingException
     {
         jgen.writeStartArray();
         jgen.writeString(idFromValue(value));
         jgen.writeStartObject();
     }
 
     @Override
     public void writeTypePrefixForObject(Object valueJsonGenerator jgen,
             Class<?> type)
         throws IOExceptionJsonProcessingException
     {
         jgen.writeStartArray();
         jgen.writeString(idFromValueAndType(valuetype));
         jgen.writeStartObject();
     }
     
     @Override
     public void writeTypePrefixForArray(Object valueJsonGenerator jgen)
         throws IOExceptionJsonProcessingException
     {
         jgen.writeStartArray();
         jgen.writeString(idFromValue(value));
         jgen.writeStartArray();
     }
 
     @Override
     public void writeTypePrefixForArray(Object valueJsonGenerator jgen,
             Class<?> type)
         throws IOExceptionJsonProcessingException
     {
         jgen.writeStartArray();
         jgen.writeString(idFromValueAndType(valuetype));
         jgen.writeStartArray();
     }
     
     @Override
     public void writeTypePrefixForScalar(Object valueJsonGenerator jgen)
             throws IOExceptionJsonProcessingException
     {
         // only need the wrapper array
         jgen.writeStartArray();
         jgen.writeString(idFromValue(value));
     }
 
     @Override
     public void writeTypePrefixForScalar(Object valueJsonGenerator jgen,
             Class<?> type)
         throws IOExceptionJsonProcessingException
     {
         // only need the wrapper array
         jgen.writeStartArray();
         jgen.writeString(idFromValueAndType(valuetype));
     }
 
     /*
     /**********************************************************
     /* Writing suffixes
    /**********************************************************
     */
    
    @Override
    public void writeTypeSuffixForObject(Object valueJsonGenerator jgen)
            throws IOExceptionJsonProcessingException
    {
        jgen.writeEndObject();
        jgen.writeEndArray();
    }
    @Override
    public void writeTypeSuffixForArray(Object valueJsonGenerator jgen)
            throws IOExceptionJsonProcessingException
    {
        // wrapper array first, and then array caller needs to close
        jgen.writeEndArray();
        jgen.writeEndArray();
    }
    @Override
    public void writeTypeSuffixForScalar(Object valueJsonGenerator jgen)
            throws IOExceptionJsonProcessingException
    {
        // just the wrapper array to close
        jgen.writeEndArray();
    }
    
    /*
    /**********************************************************
    /* Writing with custom type id
    /**********************************************************
     */
    @Override
    public void writeCustomTypePrefixForObject(Object valueJsonGenerator jgenString typeId)
        throws IOExceptionJsonProcessingException {
        jgen.writeStartArray();
        jgen.writeString(typeId);
        jgen.writeStartObject();
    }
    
    @Override
    public void writeCustomTypePrefixForArray(Object valueJsonGenerator jgenString typeId)
        throws IOExceptionJsonProcessingException
    {
        jgen.writeStartArray();
        jgen.writeString(typeId);
        jgen.writeStartArray();
    }
    @Override
    public void writeCustomTypePrefixForScalar(Object valueJsonGenerator jgenString typeId)
        throws IOExceptionJsonProcessingException
    {
        jgen.writeStartArray();
        jgen.writeString(typeId);
    }
    @Override
    public void writeCustomTypeSuffixForObject(Object valueJsonGenerator jgenString typeId)
        throws IOExceptionJsonProcessingException {
        writeTypeSuffixForObject(valuejgen); // standard impl works fine
    }
    @Override
    public void writeCustomTypeSuffixForArray(Object valueJsonGenerator jgenString typeId)
            throws IOExceptionJsonProcessingException {
        writeTypeSuffixForArray(valuejgen); // standard impl works fine
    }
    @Override
    public void writeCustomTypeSuffixForScalar(Object valueJsonGenerator jgenString typeId)
        throws IOExceptionJsonProcessingException {
        writeTypeSuffixForScalar(valuejgen); // standard impl works fine
    }
New to GrepCode? Check out our FAQ X