Top Description Inners Constructors Methods
com.fasterxml.jackson.databind.ser.std

public Class NumberSerializers

extends Object
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, java.lang.reflect.Type, java.math.BigDecimal, java.util.Map, com.fasterxml.jackson.annotation.JsonFormat, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.io.NumberOutput, com.fasterxml.jackson.core.type.WritableTypeId, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.annotation.JacksonStdImpl, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, com.fasterxml.jackson.databind.jsontype.TypeSerializer, com.fasterxml.jackson.databind.ser.ContextualSerializer

Container class for serializers used for handling standard JDK-provided primitve number types and their wrapper counterparts (like java.lang.Integer).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
NumberSerializers.Base<T>

References Deprecated StdScalarSerializer is deprecated or references (maybe indirectly) at least one deprecated element.
Shared base class for actual primitive/wrapper number serializers.
public static class
NumberSerializers.DoubleSerializer

References Deprecated NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.
This is the special serializer for regular java.lang.Doubles (and primitive doubles)

Since this is one of "native" types, no type information is ever included on serialization (unlike for most scalar types other than long).

public static class
NumberSerializers.FloatSerializer

References Deprecated NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.
public static class
NumberSerializers.IntegerSerializer

References Deprecated NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.
This is the special serializer for regular java.lang.Integers (and primitive ints)

Since this is one of "natural" types, no type information is ever included on serialization (unlike for most scalar types, except for double).

public static class
NumberSerializers.IntLikeSerializer

References Deprecated NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.
Similar to IntegerSerializer, but will not cast to Integer: instead, cast is to java.lang.Number, and conversion is by calling java.lang.Number#intValue.
public static class
NumberSerializers.LongSerializer

References Deprecated NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.
public static class
NumberSerializers.ShortSerializer

References Deprecated NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static void
addAll(Map<String, JsonSerializer<?>> allDeserializers)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NumberSerializersback to summary
protected NumberSerializers()

Method Detail

addAllback to summary
public static void addAll(Map<String, JsonSerializer<?>> allDeserializers)
com.fasterxml.jackson.databind.ser.std back to summary

public abstract Class NumberSerializers.Base<T>

extends StdScalarSerializer<T>
implements ContextualSerializer
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.databind.ser.ContextualSerializer
Known Direct Subclasses
com.fasterxml.jackson.databind.ser.std.NumberSerializers.ShortSerializer, com.fasterxml.jackson.databind.ser.std.NumberSerializers.IntegerSerializer, com.fasterxml.jackson.databind.ser.std.NumberSerializers.IntLikeSerializer, com.fasterxml.jackson.databind.ser.std.NumberSerializers.LongSerializer, com.fasterxml.jackson.databind.ser.std.NumberSerializers.FloatSerializer, com.fasterxml.jackson.databind.ser.std.NumberSerializers.DoubleSerializer

References Deprecated

StdScalarSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Shared base class for actual primitive/wrapper number serializers. Note that this class is not meant as general-purpose base class nor is it part of public API: you may extend it with the caveat that not being part of public API its implementation and interfaces may change in minor releases; however deprecation markers will be used to allow code evolution.

Note

public since 2.10: previously had protected access.

Field Summary

Modifier and TypeField and Description
protected final boolean
protected final JsonParser.NumberType
protected final String

Constructor Summary

AccessConstructor and Description
protected
Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType)

Method Summary

Modifier and TypeMethod and Description
public void
public JsonSerializer<?>
createContextual(SerializerProvider
Serializer provider to use for accessing config, other serializers
prov
,
BeanProperty
Method or field that represents the property (and is used to access value to serialize). Should be available; but there may be cases where caller cannot provide it and null is passed instead (in which case impls usually pass 'this' serializer as is)
property
)

Implements com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property.

public JsonNode
getSchema(SerializerProvider
The serializer provider.
provider
,
Type
A hint about the type.
typeHint
)

Overrides com.fasterxml.jackson.databind.ser.std.StdScalarSerializer.getSchema.

Implements com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Deprecated Since 2.15

Default implementation simply claims type is "string"; usually overriden by custom serializers.

Inherited from com.fasterxml.jackson.databind.ser.std.StdScalarSerializer:
serializeWithType

Field Detail

_isIntback to summary
protected final boolean _isInt
_numberTypeback to summary
protected final JsonParser.NumberType _numberType
_schemaTypeback to summary
protected final String _schemaType

Constructor Detail

Baseback to summary
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType)

Method Detail

acceptJsonFormatVisitorback to summary
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException

Overrides com.fasterxml.jackson.databind.ser.std.StdScalarSerializer.acceptJsonFormatVisitor.

Implements com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Doc from com.fasterxml.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Default implementation specifies no format. This behavior is usually overriden by custom serializers.

Parameters
typeHint:JavaType

Doc from com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Type of element (entity like property) being visited

Annotations
@Override
createContextualback to summary
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException

Implements com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Doc from com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property. Note that instance that this method is called on is typically shared one and as a result method should NOT modify this instance but rather construct and return a new instance. This instance should only be returned as-is, in case it is already suitable for use.

Parameters
prov:SerializerProvider

Serializer provider to use for accessing config, other serializers

property:BeanProperty

Method or field that represents the property (and is used to access value to serialize). Should be available; but there may be cases where caller cannot provide it and null is passed instead (in which case impls usually pass 'this' serializer as is)

Returns:JsonSerializer<?>

Serializer to use for serializing values of specified property; may be this instance or a new instance.

Annotations
@Override
getSchemaback to summary
public JsonNode getSchema(SerializerProvider provider, Type typeHint)

Overrides com.fasterxml.jackson.databind.ser.std.StdScalarSerializer.getSchema.

Implements com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Doc from com.fasterxml.jackson.databind.ser.std.StdSerializer.getSchema.

Deprecated

Since 2.15

Default implementation simply claims type is "string"; usually overriden by custom serializers.

Parameters
provider:SerializerProvider

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

The serializer provider.

typeHint:Type

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

A hint about the type.

Returns:JsonNode

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Json-schema for this serializer.

Annotations
@Deprecated
@Override
com.fasterxml.jackson.databind.ser.std back to summary

public Class NumberSerializers.DoubleSerializer

extends NumberSerializers.Base<Object>
Class Inheritance
Annotations
@JacksonStdImpl

References Deprecated

NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

This is the special serializer for regular java.lang.Doubles (and primitive doubles)

Since this is one of "native" types, no type information is ever included on serialization (unlike for most scalar types other than long).

Field Summary

Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
_isInt_numberType_schemaType

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean
notFinite(double value)
Deprecated

public void
serialize(Object
Value to serialize; can not be null.
value
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
)

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

public void
serializeWithType(Object
Value to serialize; can not be null.
value
,
JsonGenerator
Generator used to output resulting Json content
g
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
,
TypeSerializer
Type serializer to use for including type information
typeSer
)

Overrides com.fasterxml.jackson.databind.ser.std.StdScalarSerializer.serializeWithType.

Default implementation will write type prefix, call regular serialization method (since assumption is that value itself does not need JSON Array or Object start/end markers), and then write type suffix.

Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
acceptJsonFormatVisitorcreateContextualgetSchema

Constructor Detail

DoubleSerializerback to summary
public DoubleSerializer(Class<?> cls)

Method Detail

notFiniteback to summary
public static boolean notFinite(double value)

Deprecated

Annotations
@Deprecated
serializeback to summary
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Parameters
value:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

Annotations
@Override
serializeWithTypeback to summary
public void serializeWithType(Object value, JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer) throws IOException

Overrides com.fasterxml.jackson.databind.ser.std.StdScalarSerializer.serializeWithType.

Doc from com.fasterxml.jackson.databind.ser.std.StdScalarSerializer.serializeWithType.

Default implementation will write type prefix, call regular serialization method (since assumption is that value itself does not need JSON Array or Object start/end markers), and then write type suffix. This should work for most cases; some sub-classes may want to change this behavior.

Parameters
value:Object

Doc from com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Value to serialize; can not be null.

g:JsonGenerator

Doc from com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Generator used to output resulting Json content

provider:SerializerProvider

Doc from com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Provider that can be used to get serializers for serializing Objects value contains, if any.

typeSer:TypeSerializer

Doc from com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Type serializer to use for including type information

Annotations
@Override
com.fasterxml.jackson.databind.ser.std back to summary

public Class NumberSerializers.FloatSerializer

extends NumberSerializers.Base<Object>
Class Inheritance
Annotations
@JacksonStdImpl

References Deprecated

NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Field Summary

Modifier and TypeField and Description
pack-priv static final NumberSerializers.FloatSerializer
instance

References Deprecated NumberSerializers.FloatSerializer is deprecated or references (maybe indirectly) at least one deprecated element.
Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
_isInt_numberType_schemaType

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
serialize(Object
Value to serialize; can not be null.
value
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
)

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
acceptJsonFormatVisitorcreateContextualgetSchema

Field Detail

instanceback to summary
pack-priv static final NumberSerializers.FloatSerializer instance

References Deprecated

NumberSerializers.FloatSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Constructor Detail

FloatSerializerback to summary
public FloatSerializer()

Method Detail

serializeback to summary
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Parameters
value:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

Annotations
@Override
com.fasterxml.jackson.databind.ser.std back to summary

public Class NumberSerializers.IntegerSerializer

extends NumberSerializers.Base<Object>
Class Inheritance
Annotations
@JacksonStdImpl

References Deprecated

NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

This is the special serializer for regular java.lang.Integers (and primitive ints)

Since this is one of "natural" types, no type information is ever included on serialization (unlike for most scalar types, except for double).

Note

as of 2.6, generic signature changed to Object, to avoid generation of bridge methods.

Field Summary

Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
_isInt_numberType_schemaType

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
serialize(Object
Value to serialize; can not be null.
value
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
)

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

public void
serializeWithType(Object
Value to serialize; can not be null.
value
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
,
TypeSerializer
Type serializer to use for including type information
typeSer
)

Overrides com.fasterxml.jackson.databind.ser.std.StdScalarSerializer.serializeWithType.

Default implementation will write type prefix, call regular serialization method (since assumption is that value itself does not need JSON Array or Object start/end markers), and then write type suffix.

Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
acceptJsonFormatVisitorcreateContextualgetSchema

Constructor Detail

IntegerSerializerback to summary
public IntegerSerializer(Class<?> type)

Method Detail

serializeback to summary
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Parameters
value:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

Annotations
@Override
serializeWithTypeback to summary
public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException

Overrides com.fasterxml.jackson.databind.ser.std.StdScalarSerializer.serializeWithType.

Doc from com.fasterxml.jackson.databind.ser.std.StdScalarSerializer.serializeWithType.

Default implementation will write type prefix, call regular serialization method (since assumption is that value itself does not need JSON Array or Object start/end markers), and then write type suffix. This should work for most cases; some sub-classes may want to change this behavior.

Parameters
value:Object

Doc from com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Value to serialize; can not be null.

gen:JsonGenerator

Doc from com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Generator used to output resulting Json content

provider:SerializerProvider

Doc from com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Provider that can be used to get serializers for serializing Objects value contains, if any.

typeSer:TypeSerializer

Doc from com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Type serializer to use for including type information

Annotations
@Override
com.fasterxml.jackson.databind.ser.std back to summary

public Class NumberSerializers.IntLikeSerializer

extends NumberSerializers.Base<Object>
Class Inheritance
Annotations
@JacksonStdImpl

References Deprecated

NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Similar to IntegerSerializer, but will not cast to Integer: instead, cast is to java.lang.Number, and conversion is by calling java.lang.Number#intValue.

Field Summary

Modifier and TypeField and Description
pack-priv static final NumberSerializers.IntLikeSerializer
instance

References Deprecated NumberSerializers.IntLikeSerializer is deprecated or references (maybe indirectly) at least one deprecated element.
Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
_isInt_numberType_schemaType

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
serialize(Object
Value to serialize; can not be null.
value
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
)

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
acceptJsonFormatVisitorcreateContextualgetSchema

Field Detail

instanceback to summary
pack-priv static final NumberSerializers.IntLikeSerializer instance

References Deprecated

NumberSerializers.IntLikeSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Constructor Detail

IntLikeSerializerback to summary
public IntLikeSerializer()

Method Detail

serializeback to summary
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Parameters
value:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

Annotations
@Override
com.fasterxml.jackson.databind.ser.std back to summary

public Class NumberSerializers.LongSerializer

extends NumberSerializers.Base<Object>
Class Inheritance
Annotations
@JacksonStdImpl

References Deprecated

NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Field Summary

Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
_isInt_numberType_schemaType

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
serialize(Object
Value to serialize; can not be null.
value
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
)

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
acceptJsonFormatVisitorcreateContextualgetSchema

Constructor Detail

LongSerializerback to summary
public LongSerializer(Class<?> cls)

Method Detail

serializeback to summary
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Parameters
value:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

Annotations
@Override
com.fasterxml.jackson.databind.ser.std back to summary

public Class NumberSerializers.ShortSerializer

extends NumberSerializers.Base<Object>
Class Inheritance
Annotations
@JacksonStdImpl

References Deprecated

NumberSerializers.Base is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Field Summary

Modifier and TypeField and Description
pack-priv static final NumberSerializers.ShortSerializer
instance

References Deprecated NumberSerializers.ShortSerializer is deprecated or references (maybe indirectly) at least one deprecated element.
Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
_isInt_numberType_schemaType

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
serialize(Object
Value to serialize; can not be null.
value
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
)

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Inherited from com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base:
acceptJsonFormatVisitorcreateContextualgetSchema

Field Detail

instanceback to summary
pack-priv static final NumberSerializers.ShortSerializer instance

References Deprecated

NumberSerializers.ShortSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Constructor Detail

ShortSerializerback to summary
public ShortSerializer()

Method Detail

serializeback to summary
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Parameters
value:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

Annotations
@Override