Class RangeSerializer

  • All Implemented Interfaces:
    com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, com.fasterxml.jackson.databind.jsonschema.SchemaAware, com.fasterxml.jackson.databind.ser.ContextualSerializer, java.io.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:

    {@code
    See Also:
    Serialized Form
    • 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 com.fasterxml.jackson.databind.JsonSerializer<java.lang.Object> _endpointSerializer  
      protected RangeHelper.RangeProperties _fieldNames  
      protected com.fasterxml.jackson.databind.JavaType _rangeType  
      protected com.fasterxml.jackson.annotation.JsonFormat.Shape _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

      All Methods Instance Methods Concrete Methods 
      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 java.lang.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 Detail

      • _rangeType

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

        protected final com.fasterxml.jackson.databind.JsonSerializer<java.lang.Object> _endpointSerializer
      • _shape

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

      • 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 Detail

      • 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 java.io.IOException,
                              com.fasterxml.jackson.core.JsonGenerationException
        Specified by:
        serialize in class com.fasterxml.jackson.databind.ser.std.StdSerializer<com.google.common.collect.Range<?>>
        Throws:
        java.io.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 java.io.IOException
        Overrides:
        serializeWithType in class com.fasterxml.jackson.databind.JsonSerializer<com.google.common.collect.Range<?>>
        Throws:
        java.io.IOException
      • getStringFormat

        protected java.lang.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 java.io.IOException
        Throws:
        java.io.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