Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.ser.std;
 
 
 
This is a simple dummy serializer that will just output raw values by calling toString() on value to serialize.
public class RawSerializer<T>
    extends StdSerializer<T>
{
    
Constructor takes in expected type of values; but since caller typically can not really provide actual type parameter, we will just take wild card and coerce type.
    public RawSerializer(Class<?> cls) {
        super(clsfalse);
    }
    @Override
    public void serialize(T valueJsonGenerator jgenSerializerProvider provider)
        throws IOExceptionJsonGenerationException
    {
        jgen.writeRawValue(value.toString());
    }
    @Override
    public void serializeWithType(T valueJsonGenerator jgenSerializerProvider provider,
            TypeSerializer typeSer)
        throws IOExceptionJsonProcessingException
    {
        typeSer.writeTypePrefixForScalar(valuejgen);
        serialize(valuejgenprovider);
        typeSer.writeTypeSuffixForScalar(valuejgen);
    }
    
    @Override
    public JsonNode getSchema(SerializerProvider providerType typeHint)
    {
        // type not really known, but since it is a JSON string:
        return createSchemaNode("string"true);
    }
    
    @Override
    public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitorJavaType typeHint)
        throws JsonMappingException
    {
        visitor.expectStringFormat(typeHint);
    }
New to GrepCode? Check out our FAQ X