Class MonetaryToBigDecimalConverter

java.lang.Object
com.fasterxml.jackson.databind.util.StdConverter<javax.money.MonetaryAmount,BigDecimal>
com.broadleafcommerce.money.jackson.MonetaryToBigDecimalConverter
All Implemented Interfaces:
com.fasterxml.jackson.databind.util.Converter<javax.money.MonetaryAmount,BigDecimal>

public class MonetaryToBigDecimalConverter extends com.fasterxml.jackson.databind.util.StdConverter<javax.money.MonetaryAmount,BigDecimal>

On an incoming deserialization request, we should not trust the currency coming in at all and instead only look at the value. However, we do want to support the MonetaryValue shape to make it easy for clients using the API to serialize results to. This allows us to take in a deserialization request that looks like a MonetaryAmount but still set just the BigDecimal as the property.

Note that this will only accept JSON that looks like a Money (nested object). If you want to support both nested and non-nested values, consider OptionalMonetaryAmountDeserializer

Author:
Phillip Verheyden (phillipuniverse)
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.util.Converter

    com.fasterxml.jackson.databind.util.Converter.None
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    convert(javax.money.MonetaryAmount value)
     

    Methods inherited from class com.fasterxml.jackson.databind.util.StdConverter

    _findConverterType, getInputType, getOutputType

    Methods inherited from class java.lang.Object

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

    • MonetaryToBigDecimalConverter

      public MonetaryToBigDecimalConverter()
  • Method Details

    • convert

      public BigDecimal convert(javax.money.MonetaryAmount value)
      Specified by:
      convert in interface com.fasterxml.jackson.databind.util.Converter<javax.money.MonetaryAmount,BigDecimal>
      Specified by:
      convert in class com.fasterxml.jackson.databind.util.StdConverter<javax.money.MonetaryAmount,BigDecimal>