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
By default, when the range property lacks the string shape annotation, the serializer will output the JSON in following manner:
@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
FieldsModifier and TypeFieldDescriptionprotected final com.fasterxml.jackson.databind.JsonSerializer
<Object> protected final RangeHelper.RangeProperties
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
ConstructorsConstructorDescriptionRangeSerializer
(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.17RangeSerializer
(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 TypeMethodDescriptionprotected 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
-
Field Details
-
_rangeType
protected final com.fasterxml.jackson.databind.JavaType _rangeType -
_endpointSerializer
-
_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 classcom.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 interfacecom.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 classcom.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 classcom.fasterxml.jackson.databind.JsonSerializer<com.google.common.collect.Range<?>>
- Throws:
IOException
-
getStringFormat
-
_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 interfacecom.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
- Overrides:
acceptJsonFormatVisitor
in classcom.fasterxml.jackson.databind.ser.std.StdSerializer<com.google.common.collect.Range<?>>
- Throws:
com.fasterxml.jackson.databind.JsonMappingException
-