Class DoubleSerializer
- All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
,com.fasterxml.jackson.databind.jsonschema.SchemaAware
,Serializable
A custom serializer for
Double
values, extending StdSerializer
.
This serializer handles special cases of floating-point numbers, converting them
to their textual representations in JSON.
Special handling is provided for:
Double.POSITIVE_INFINITY
andDouble.MAX_VALUE
: serialized as "Infinity".Double.NEGATIVE_INFINITY
and-Double.MAX_VALUE
: serialized as "-Infinity".Double.NaN
: serialized as "NaN".- All other
Double
values: serialized as standard numeric values.
- 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 inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
_handledType
-
Constructor Summary
-
Method Summary
Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
_neitherNull, _nonEmpty, acceptJsonFormatVisitor, 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, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, serializeWithType, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties
-
Constructor Details
-
DoubleSerializer
public DoubleSerializer()Default constructor. Initializes the serializer forDouble
type.
-
-
Method Details
-
serialize
public void serialize(Double value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider provider) throws IOException Serializes aDouble
value into JSON.Converts special floating-point values into their respective textual representations:
- "Infinity" for
Double.POSITIVE_INFINITY
andDouble.MAX_VALUE
. - "-Infinity" for
Double.NEGATIVE_INFINITY
and-Double.MAX_VALUE
. - "NaN" for
Double.NaN
. - Other numeric values are serialized as numbers.
- Specified by:
serialize
in classcom.fasterxml.jackson.databind.ser.std.StdSerializer<Double>
- Parameters:
value
- theDouble
value to serialize.gen
- theJsonGenerator
used to write JSON content.provider
- theSerializerProvider
for accessing serialization configuration.- Throws:
IOException
- if an I/O error occurs during serialization.
- "Infinity" for
-