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 "external" type property; embedded in enclosing JSON object. Note that this serializer should only be used when value is being output at JSON Object context; otherwise it can not work reliably, and will have to revert operation similar to AsPropertyTypeSerializer.

Note that implementation of serialization is bit cumbersome as we must serialized external type id AFTER object; this because callback only occurs after field name has been written.

 
    extends TypeSerializerBase
 {
    protected final String _typePropertyName;
 
    public AsExternalTypeSerializer(TypeIdResolver idResBeanProperty property,
           String propName)
    {
        super(idResproperty);
         = propName;
    }
 
    @Override
        if ( == propreturn this;
        return new AsExternalTypeSerializer(prop);
    }
    
    @Override
    public String getPropertyName() { return ; }
 
    @Override
    public As getTypeInclusion() { return .; }
 
    /*
    /**********************************************************
    /* Writing prefixes
    /**********************************************************
     */
    
    @Override
    public void writeTypePrefixForObject(Object valueJsonGenerator jgen)
        throws IOExceptionJsonProcessingException
    {
        _writeObjectPrefix(valuejgen);
    }
 
    @Override
    public void writeTypePrefixForObject(Object valueJsonGenerator jgenClass<?> type)
        throws IOExceptionJsonProcessingException
    {
        _writeObjectPrefix(valuejgen);
    }
    
    @Override
    public void writeTypePrefixForArray(Object valueJsonGenerator jgen)
        throws IOExceptionJsonProcessingException
    {
        _writeArrayPrefix(valuejgen);
    }
 
    @Override
    public void writeTypePrefixForArray(Object valueJsonGenerator jgenClass<?> type)
            throws IOExceptionJsonProcessingException
    {
        _writeArrayPrefix(valuejgen);
    }
 
    @Override
    public void writeTypePrefixForScalar(Object valueJsonGenerator jgen)
            throws IOExceptionJsonProcessingException
    {
        _writeScalarPrefix(valuejgen);
    }
 
    @Override
    public void writeTypePrefixForScalar(Object valueJsonGenerator jgenClass<?> type)
            throws IOExceptionJsonProcessingException
    {
        _writeScalarPrefix(valuejgen);
    }
 
    /*
    /**********************************************************
    /* Writing suffixes
    /**********************************************************
     */
    
   public void writeTypeSuffixForObject(Object valueJsonGenerator jgen)
       throws IOExceptionJsonProcessingException
   {
       _writeObjectSuffix(valuejgenidFromValue(value));
   }
   public void writeTypeSuffixForArray(Object valueJsonGenerator jgen)
       throws IOExceptionJsonProcessingException
   {
       _writeArraySuffix(valuejgenidFromValue(value));
   }
   
   public void writeTypeSuffixForScalar(Object valueJsonGenerator jgen)
       throws IOExceptionJsonProcessingException
   {
       _writeScalarSuffix(valuejgenidFromValue(value));
   }
   /*
   /**********************************************************
   /* Writing with custom type id
   /**********************************************************
    */
   public void writeCustomTypePrefixForScalar(Object valueJsonGenerator jgenString typeId)
       throws IOExceptionJsonProcessingException
   {
       _writeScalarPrefix(valuejgen);
   }
   
   public void writeCustomTypePrefixForObject(Object valueJsonGenerator jgenString typeId)
       throws IOExceptionJsonProcessingException {
       _writeObjectPrefix(valuejgen);
   }
   
   public void writeCustomTypePrefixForArray(Object valueJsonGenerator jgenString typeId)
       throws IOExceptionJsonProcessingException
   {
       _writeArrayPrefix(valuejgen);
   }
   public void writeCustomTypeSuffixForScalar(Object valueJsonGenerator jgenString typeId)
       throws IOExceptionJsonProcessingException {
       _writeScalarSuffix(valuejgentypeId);
   }
   public void writeCustomTypeSuffixForObject(Object valueJsonGenerator jgenString typeId)
       throws IOExceptionJsonProcessingException {
       _writeObjectSuffix(valuejgentypeId);
   }
   public void writeCustomTypeSuffixForArray(Object valueJsonGenerator jgenString typeId)
           throws IOExceptionJsonProcessingException {
       _writeArraySuffix(valuejgentypeId);
   }
   
   /*
   /**********************************************************
   /* Helper methods
   /**********************************************************
    */
   protected final void _writeScalarPrefix(Object valueJsonGenerator jgen)
       throws IOExceptionJsonProcessingException {
       // nothing to wrap it with
   }
   protected final void _writeObjectPrefix(Object valueJsonGenerator jgen)
       throws IOExceptionJsonProcessingException {
       jgen.writeStartObject();
   }
   protected final void _writeArrayPrefix(Object valueJsonGenerator jgen)
       throws IOExceptionJsonProcessingException {
       jgen.writeStartArray();
   }
   
   protected final void _writeScalarSuffix(Object valueJsonGenerator jgenString typeId)
       throws IOExceptionJsonProcessingException
   {
       jgen.writeStringField(typeId);
   }
   
   protected final void _writeObjectSuffix(Object valueJsonGenerator jgenString typeId)
       throws IOExceptionJsonProcessingException
   {
       jgen.writeEndObject();
       jgen.writeStringField(typeId);
   }
   protected final void _writeArraySuffix(Object valueJsonGenerator jgenString typeId)
       throws IOExceptionJsonProcessingException
   {
       jgen.writeEndArray();
       jgen.writeStringField(typeId);
   }
New to GrepCode? Check out our FAQ X