Class CurrencyAwareBigDecimalSerializer
java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<T>
com.fasterxml.jackson.databind.ser.std.StdSerializer<BigDecimal>
com.broadleafcommerce.money.jackson.CurrencyAwareBigDecimalSerializer
- All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
,com.fasterxml.jackson.databind.jsonschema.SchemaAware
,Serializable
public class CurrencyAwareBigDecimalSerializer
extends com.fasterxml.jackson.databind.ser.std.StdSerializer<BigDecimal>
Serializes a BigDecimal property to look like MonetaryAmount with a currency. This is used when serialization domain should have all BigDecimal properties representing money but the frontend should see an amount with currency.
Objects whose properties use this serializer should also implement CurrencyContextAware
so that this serializer knows the exact contextual currency relationship. If the parent object
does not implement CurrencyContextAware
a warning is logged and the system default
currency is used.
Example usage:
@Data
public class Product implments CurrencyContextAware {@JsonIgnore
CurrencyContext currencyContext@JsonSerialize(CurrencyAwareBigDecimalSerializer.class
private BigDecimal price; }
- Author:
- Phillip Verheyden (phillipuniverse)
- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptJsonFormatVisitor
(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper wrapper, com.fasterxml.jackson.databind.JavaType hint) protected javax.money.CurrencyUnit
resolveCurrency
(Object parentSerializedObject) void
serialize
(BigDecimal value, com.fasterxml.jackson.core.JsonGenerator generator, com.fasterxml.jackson.databind.SerializerProvider provider) void
serializeWithType
(BigDecimal value, com.fasterxml.jackson.core.JsonGenerator generator, com.fasterxml.jackson.databind.SerializerProvider provider, com.fasterxml.jackson.databind.jsontype.TypeSerializer serializer) 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, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId
-
Constructor Details
-
CurrencyAwareBigDecimalSerializer
protected CurrencyAwareBigDecimalSerializer()
-
-
Method Details
-
acceptJsonFormatVisitor
public void acceptJsonFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper wrapper, com.fasterxml.jackson.databind.JavaType hint) 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<BigDecimal>
- Throws:
com.fasterxml.jackson.databind.JsonMappingException
-
serializeWithType
public void serializeWithType(BigDecimal value, com.fasterxml.jackson.core.JsonGenerator generator, com.fasterxml.jackson.databind.SerializerProvider provider, com.fasterxml.jackson.databind.jsontype.TypeSerializer serializer) throws IOException - Overrides:
serializeWithType
in classcom.fasterxml.jackson.databind.JsonSerializer<BigDecimal>
- Throws:
IOException
-
serialize
public void serialize(BigDecimal value, com.fasterxml.jackson.core.JsonGenerator generator, com.fasterxml.jackson.databind.SerializerProvider provider) throws IOException - Specified by:
serialize
in classcom.fasterxml.jackson.databind.ser.std.StdSerializer<BigDecimal>
- Throws:
IOException
-
resolveCurrency
-