Package io.objectbox.converter
Class FlexObjectConverter
java.lang.Object
io.objectbox.converter.FlexObjectConverter
- All Implemented Interfaces:
PropertyConverter<Object,
byte[]>
- Direct Known Subclasses:
IntegerFlexMapConverter
,LongFlexMapConverter
,StringFlexMapConverter
Converts between
Object
properties and byte arrays using FlexBuffers.
Types are limited to those supported by FlexBuffers, including that map keys must be String
.
(There are subclasses available that auto-convert Integer
and Long
key maps,
see convertToKey(java.lang.String)
.)
If any item requires 64 bits for storage in the FlexBuffers Map/Vector (a large Long, a Double)
all integers are restored as Long
, otherwise Integer
.
So e.g. when storing only a Long
value of 1L
, the value restored from the
database will be of type Integer
.
(There are subclasses available that always restore as Long
, see shouldRestoreAsLong(io.objectbox.flatbuffers.FlexBuffers.Reference)
.)
Values of type Float
are always restored as Double
.
Cast to Float
to obtain the original value.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkMapKeyType
(Object rawKey) Checks Java map key is of the expected type, otherwise throws.byte[]
convertToDatabaseValue
(Object value) convertToEntityProperty
(byte[] databaseValue) protected boolean
shouldRestoreAsLong
(io.objectbox.flatbuffers.FlexBuffers.Reference reference) Returns true if the width in bytes stored in the private parentWidth field of FlexBuffers.Reference is 8.
-
Constructor Details
-
FlexObjectConverter
public FlexObjectConverter()
-
-
Method Details
-
convertToDatabaseValue
- Specified by:
convertToDatabaseValue
in interfacePropertyConverter<Object,
byte[]>
-
checkMapKeyType
Checks Java map key is of the expected type, otherwise throws. -
convertToEntityProperty
- Specified by:
convertToEntityProperty
in interfacePropertyConverter<Object,
byte[]>
-
shouldRestoreAsLong
protected boolean shouldRestoreAsLong(io.objectbox.flatbuffers.FlexBuffers.Reference reference) Returns true if the width in bytes stored in the private parentWidth field of FlexBuffers.Reference is 8. Note: FlexBuffers stores all items in a map/vector using the size of the widest item. However, an item's size is only as wide as needed, e.g. a 64-bit integer (Java Long, 8 bytes) will be reduced to 1 byte if it does not exceed its value range.
-