Class OptionalMonetaryAmountDeserializer
java.lang.Object
com.fasterxml.jackson.databind.JsonDeserializer<BigDecimal>
com.broadleafcommerce.money.jackson.OptionalMonetaryAmountDeserializer
- All Implemented Interfaces:
com.fasterxml.jackson.databind.deser.NullValueProvider
public class OptionalMonetaryAmountDeserializer
extends com.fasterxml.jackson.databind.JsonDeserializer<BigDecimal>
Takes in JSON that looks like it was formatted for a Money object but deserializes just the amount field into a BigDecimal. This also accepts JSON that looks like it just has a value.
For example, an object that looks like this:
public class Product {
@Getter
@Setter
@JsonDeserialize(using = OptionalMonetaryAmountDeserializer.class)
BigDecimal price;
}
will accept either one of these JSON strings:
{
"price": {
"amount": 5.00
}
}
or
{
"price": 5.00
}
- Author:
- Phillip Verheyden (phillipuniverse)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonDeserializer
com.fasterxml.jackson.databind.JsonDeserializer.None -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondeserialize(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.databind.DeserializationContext context) deserializeWithType(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.databind.DeserializationContext context, com.fasterxml.jackson.databind.jsontype.TypeDeserializer deserializer) Methods inherited from class com.fasterxml.jackson.databind.JsonDeserializer
deserialize, deserializeWithType, findBackReference, getAbsentValue, getDelegatee, getEmptyAccessPattern, getEmptyValue, getEmptyValue, getKnownPropertyNames, getNullAccessPattern, getNullValue, getNullValue, getObjectIdReader, handledType, isCachable, logicalType, replaceDelegatee, supportsUpdate, unwrappingDeserializer
-
Field Details
-
AMOUNT_FIELD
- See Also:
-
-
Constructor Details
-
OptionalMonetaryAmountDeserializer
public OptionalMonetaryAmountDeserializer()
-
-
Method Details
-
deserializeWithType
public Object deserializeWithType(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.databind.DeserializationContext context, com.fasterxml.jackson.databind.jsontype.TypeDeserializer deserializer) throws IOException - Overrides:
deserializeWithTypein classcom.fasterxml.jackson.databind.JsonDeserializer<BigDecimal>- Throws:
IOException
-
deserialize
public BigDecimal deserialize(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.databind.DeserializationContext context) throws IOException - Specified by:
deserializein classcom.fasterxml.jackson.databind.JsonDeserializer<BigDecimal>- Throws:
IOException
-