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
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    deserialize(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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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:
      deserializeWithType in class com.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:
      deserialize in class com.fasterxml.jackson.databind.JsonDeserializer<BigDecimal>
      Throws:
      IOException