Package dev.morphia.converters
Class BigDecimalConverter
- java.lang.Object
-
- dev.morphia.converters.TypeConverter
-
- dev.morphia.converters.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 Summary
Constructors Constructor Description BigDecimalConverter()
Creates the Converter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
decode(java.lang.Class<?> targetClass, java.lang.Object value, MappedField optionalExtraInfo)
decode theDBObject
and provide the corresponding java (type-safe) object
NOTE: optionalExtraInfo might be nulljava.lang.Object
encode(java.lang.Object value, MappedField optionalExtraInfo)
encode the (type-safe) java object into the correspondingDBObject
-
Methods inherited from class dev.morphia.converters.TypeConverter
decode, encode, equals, getMapper, getSupportTypes, hashCode, isSupported, oneOf, oneOfClasses, setMapper, setSupportedTypes, setSupportTypes
-
-
-
-
Method Detail
-
decode
public java.lang.Object decode(java.lang.Class<?> targetClass, java.lang.Object value, MappedField optionalExtraInfo)
Description copied from class:TypeConverter
decode theDBObject
and provide the corresponding java (type-safe) object
NOTE: optionalExtraInfo might be null- Specified by:
decode
in classTypeConverter
- Parameters:
targetClass
- the class to create and populatevalue
- the DBObject to use when populating the new instanceoptionalExtraInfo
- 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 correspondingDBObject
- Overrides:
encode
in classTypeConverter
- Parameters:
value
- The object to encodeoptionalExtraInfo
- the MappedField that contains the metadata useful for decoding- Returns:
- the encoded version of the object
-
-