Class RangeSerializer

java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<com.google.common.collect.Range<?>>
com.fasterxml.jackson.databind.ser.std.StdSerializer<com.google.common.collect.Range<?>>
com.fasterxml.jackson.datatype.guava.ser.RangeSerializer
All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, com.fasterxml.jackson.databind.jsonschema.SchemaAware, com.fasterxml.jackson.databind.ser.ContextualSerializer, Serializable

public class RangeSerializer extends com.fasterxml.jackson.databind.ser.std.StdSerializer<com.google.common.collect.Range<?>> implements com.fasterxml.jackson.databind.ser.ContextualSerializer
Jackson serializer for Guava Range objects with enhanced serialization capabilities. When the range property is annotated with @JsonFormat(JsonFormat.Shape.STRING), it generates bracket notation for a more concise and human-readable representation. Otherwise, it defaults to a more verbose standard serialization, explicitly writing out endpoints and bound types.

Usage Example for bracket notation:


   @JsonFormat(JsonFormat.Shape.STRING)
   private Range<Integer> r;
 
When the range field is annotated with @JsonFormat(JsonFormat.Shape.STRING), the serializer will output the range that would look something like: [X..Y] or (X..Y).

By default, when the range property lacks the string shape annotation, the serializer will output the JSON in following manner:

   {
      "lowerEndpoint": X,
      "lowerBoundType": "CLOSED",
      "upperEndpoint": Y,
      "upperBoundType": "CLOSED"
   }
 
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer

    com.fasterxml.jackson.databind.JsonSerializer.None
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final com.fasterxml.jackson.databind.JsonSerializer<Object>
     
     
    protected final com.fasterxml.jackson.databind.JavaType
     
    protected final com.fasterxml.jackson.annotation.JsonFormat.Shape
     

    Fields inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer

    _handledType
  • Constructor Summary

    Constructors
    Constructor
    Description
    RangeSerializer(com.fasterxml.jackson.databind.JavaType type)
     
    RangeSerializer(com.fasterxml.jackson.databind.JavaType type, com.fasterxml.jackson.databind.JsonSerializer<?> endpointSer)
    Deprecated.
    RangeSerializer(com.fasterxml.jackson.databind.JavaType type, com.fasterxml.jackson.databind.JsonSerializer<?> endpointSer, RangeHelper.RangeProperties fieldNames)
    Deprecated.
    Since 2.17
    RangeSerializer(com.fasterxml.jackson.databind.JavaType type, com.fasterxml.jackson.databind.JsonSerializer<?> endpointSer, RangeHelper.RangeProperties fieldNames, com.fasterxml.jackson.annotation.JsonFormat.Shape shape)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    _writeContents(com.google.common.collect.Range<?> value, com.fasterxml.jackson.core.JsonGenerator g, com.fasterxml.jackson.databind.SerializerProvider provider)
     
    void
    acceptJsonFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper visitor, com.fasterxml.jackson.databind.JavaType typeHint)
     
    com.fasterxml.jackson.databind.JsonSerializer<?>
    createContextual(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.databind.BeanProperty property)
     
    protected String
    getStringFormat(com.google.common.collect.Range<?> range)
     
    boolean
    isEmpty(com.fasterxml.jackson.databind.SerializerProvider prov, com.google.common.collect.Range<?> value)
     
    void
    serialize(com.google.common.collect.Range<?> value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider provider)
     
    void
    serializeWithType(com.google.common.collect.Range<?> value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider provider, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSer)
     

    Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer

    _neitherNull, _nonEmpty, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findConvertingContentSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, getSchema, getSchema, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrow

    Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer

    getDelegatee, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _rangeType

      protected final com.fasterxml.jackson.databind.JavaType _rangeType
    • _endpointSerializer

      protected final com.fasterxml.jackson.databind.JsonSerializer<Object> _endpointSerializer
    • _fieldNames

      protected final RangeHelper.RangeProperties _fieldNames
    • _shape

      protected final com.fasterxml.jackson.annotation.JsonFormat.Shape _shape
      Since:
      2.17
  • Constructor Details

    • RangeSerializer

      public RangeSerializer(com.fasterxml.jackson.databind.JavaType type)
    • RangeSerializer

      @Deprecated public RangeSerializer(com.fasterxml.jackson.databind.JavaType type, com.fasterxml.jackson.databind.JsonSerializer<?> endpointSer)
      Deprecated.
    • RangeSerializer

      @Deprecated public RangeSerializer(com.fasterxml.jackson.databind.JavaType type, com.fasterxml.jackson.databind.JsonSerializer<?> endpointSer, RangeHelper.RangeProperties fieldNames)
      Deprecated.
      Since 2.17
      Since:
      2.10
    • RangeSerializer

      public RangeSerializer(com.fasterxml.jackson.databind.JavaType type, com.fasterxml.jackson.databind.JsonSerializer<?> endpointSer, RangeHelper.RangeProperties fieldNames, com.fasterxml.jackson.annotation.JsonFormat.Shape shape)
      Since:
      2.17
  • Method Details

    • isEmpty

      public boolean isEmpty(com.fasterxml.jackson.databind.SerializerProvider prov, com.google.common.collect.Range<?> value)
      Overrides:
      isEmpty in class com.fasterxml.jackson.databind.JsonSerializer<com.google.common.collect.Range<?>>
    • createContextual

      public com.fasterxml.jackson.databind.JsonSerializer<?> createContextual(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.databind.BeanProperty property) throws com.fasterxml.jackson.databind.JsonMappingException
      Specified by:
      createContextual in interface com.fasterxml.jackson.databind.ser.ContextualSerializer
      Throws:
      com.fasterxml.jackson.databind.JsonMappingException
    • serialize

      public void serialize(com.google.common.collect.Range<?> value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider provider) throws IOException, com.fasterxml.jackson.core.JsonGenerationException
      Specified by:
      serialize in class com.fasterxml.jackson.databind.ser.std.StdSerializer<com.google.common.collect.Range<?>>
      Throws:
      IOException
      com.fasterxml.jackson.core.JsonGenerationException
    • serializeWithType

      public void serializeWithType(com.google.common.collect.Range<?> value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider provider, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSer) throws IOException
      Overrides:
      serializeWithType in class com.fasterxml.jackson.databind.JsonSerializer<com.google.common.collect.Range<?>>
      Throws:
      IOException
    • getStringFormat

      protected String getStringFormat(com.google.common.collect.Range<?> range)
    • _writeContents

      protected void _writeContents(com.google.common.collect.Range<?> value, com.fasterxml.jackson.core.JsonGenerator g, com.fasterxml.jackson.databind.SerializerProvider provider) throws IOException
      Throws:
      IOException
    • acceptJsonFormatVisitor

      public void acceptJsonFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper visitor, com.fasterxml.jackson.databind.JavaType typeHint) throws com.fasterxml.jackson.databind.JsonMappingException
      Specified by:
      acceptJsonFormatVisitor in interface com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
      Overrides:
      acceptJsonFormatVisitor in class com.fasterxml.jackson.databind.ser.std.StdSerializer<com.google.common.collect.Range<?>>
      Throws:
      com.fasterxml.jackson.databind.JsonMappingException