Class BigDecimalConverter

  • All Implemented Interfaces:
    SimpleValueConverter

    public class BigDecimalConverter
    extends TypeConverter
    implements SimpleValueConverter
    This provides a conversion to/from BigDecimal in applications using the Decimal128 type introduced in the 3.4.0 release of MongoDB. This converter also supports loading certain types of values from the database and converting them to BigDecimal.

    Note: While this is useful for gradual model migrations, the values will be saved as Decimal128 types when saved back. This will result in disparate types for a given field which may yield unexpected results when querying.

    Since:
    1.3
    See Also:
    Decimal128
    Since server release
    3.4
    • Constructor Detail

      • BigDecimalConverter

        public BigDecimalConverter()
        Creates the Converter.
    • Method Detail

      • decode

        public java.lang.Object decode​(java.lang.Class<?> targetClass,
                                       java.lang.Object value,
                                       MappedField optionalExtraInfo)
        Description copied from class: TypeConverter
        decode the DBObject and provide the corresponding java (type-safe) object
        NOTE: optionalExtraInfo might be null
        Specified by:
        decode in class TypeConverter
        Parameters:
        targetClass - the class to create and populate
        value - the DBObject to use when populating the new instance
        optionalExtraInfo - the MappedField that contains the metadata useful for decoding
        Returns:
        the new instance
      • encode

        public java.lang.Object encode​(java.lang.Object value,
                                       MappedField optionalExtraInfo)
        Description copied from class: TypeConverter
        encode the (type-safe) java object into the corresponding DBObject
        Overrides:
        encode in class TypeConverter
        Parameters:
        value - The object to encode
        optionalExtraInfo - the MappedField that contains the metadata useful for decoding
        Returns:
        the encoded version of the object