Class FloatSerializer
- All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
,com.fasterxml.jackson.databind.jsonschema.SchemaAware
,Serializable
A custom serializer for
Float
values, extending StdSerializer
.
This serializer handles special floating-point values, converting them into their
textual representations in JSON.
Special handling is provided for:
Float.POSITIVE_INFINITY
andFloat.MAX_VALUE
: Serialized as"Infinity"
.Float.NEGATIVE_INFINITY
and-Float.MAX_VALUE
: Serialized as"-Infinity"
.Float.NaN
: Serialized as"NaN"
.- All other valid
Float
values: Serialized as 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
-
FloatSerializer
public FloatSerializer()Default constructor. Initializes the serializer forFloat
type.
-
-
Method Details
-
serialize
public void serialize(Float value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider provider) throws IOException Serializes aFloat
value into JSON.Converts special floating-point values into their respective textual representations:
"Infinity"
forFloat.POSITIVE_INFINITY
andFloat.MAX_VALUE
."-Infinity"
forFloat.NEGATIVE_INFINITY
and-Float.MAX_VALUE
."NaN"
forFloat.NaN
.- Other numeric values are serialized as standard numbers.
- Specified by:
serialize
in classcom.fasterxml.jackson.databind.ser.std.StdSerializer<Float>
- Parameters:
value
- theFloat
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.
-