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:
@Datapublic class Product implments CurrencyContextAware {@JsonIgnoreCurrencyContext currencyContext@JsonSerialize(CurrencyAwareBigDecimalSerializer.classprivate 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 TypeMethodDescriptionvoidacceptJsonFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper wrapper, com.fasterxml.jackson.databind.JavaType hint) protected javax.money.CurrencyUnitresolveCurrency(Object parentSerializedObject) voidserialize(BigDecimal value, com.fasterxml.jackson.core.JsonGenerator generator, com.fasterxml.jackson.databind.SerializerProvider provider) voidserializeWithType(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, wrapAndThrowMethods inherited from class com.fasterxml.jackson.databind.JsonSerializer
getDelegatee, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties
-
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:
acceptJsonFormatVisitorin interfacecom.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable- Overrides:
acceptJsonFormatVisitorin 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:
serializeWithTypein 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:
serializein classcom.fasterxml.jackson.databind.ser.std.StdSerializer<BigDecimal>- Throws:
IOException
-
resolveCurrency
-