Class FlexObjectConverter
- java.lang.Object
-
- io.objectbox.converter.FlexObjectConverter
-
- All Implemented Interfaces:
PropertyConverter<java.lang.Object,byte[]>
- Direct Known Subclasses:
IntegerFlexMapConverter,LongFlexMapConverter,StringFlexMapConverter
public class FlexObjectConverter extends java.lang.Object implements PropertyConverter<java.lang.Object,byte[]>
Converts betweenObjectproperties 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-convertIntegerandLongkey maps, seeconvertToKey(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, otherwiseInteger. So e.g. when storing only aLongvalue of1L, the value restored from the database will be of typeInteger. (There are subclasses available that always restore asLong, seeshouldRestoreAsLong(io.objectbox.flatbuffers.FlexBuffers.Reference).)Values of type
Floatare always restored asDouble. Cast toFloatto obtain the original value.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.concurrent.atomic.AtomicReference<FlexBuffersBuilder>cachedBuilder
-
Constructor Summary
Constructors Constructor Description FlexObjectConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddMap(FlexBuffersBuilder builder, java.lang.String mapKey, java.util.Map<java.lang.Object,java.lang.Object> map)private voidaddValue(FlexBuffersBuilder builder, java.lang.Object value)private voidaddVector(FlexBuffersBuilder builder, java.lang.String vectorKey, java.util.List<java.lang.Object> list)private java.util.List<java.lang.Object>buildList(FlexBuffers.Vector vector)private java.util.Map<java.lang.Object,java.lang.Object>buildMap(FlexBuffers.Map map)protected voidcheckMapKeyType(java.lang.Object rawKey)Checks Java map key is of the expected type, otherwise throws.byte[]convertToDatabaseValue(java.lang.Object value)java.lang.ObjectconvertToEntityProperty(byte[] databaseValue)(package private) java.lang.ObjectconvertToKey(java.lang.String keyValue)Converts a FlexBuffers string map key to the Java map key (e.g.protected booleanshouldRestoreAsLong(FlexBuffers.Reference reference)Returns true if the width in bytes stored in the private parentWidth field of FlexBuffers.Reference is 8.
-
-
-
Field Detail
-
cachedBuilder
private static final java.util.concurrent.atomic.AtomicReference<FlexBuffersBuilder> cachedBuilder
-
-
Method Detail
-
convertToDatabaseValue
public byte[] convertToDatabaseValue(java.lang.Object value)
- Specified by:
convertToDatabaseValuein interfacePropertyConverter<java.lang.Object,byte[]>
-
addValue
private void addValue(FlexBuffersBuilder builder, java.lang.Object value)
-
checkMapKeyType
protected void checkMapKeyType(java.lang.Object rawKey)
Checks Java map key is of the expected type, otherwise throws.
-
addMap
private void addMap(FlexBuffersBuilder builder, java.lang.String mapKey, java.util.Map<java.lang.Object,java.lang.Object> map)
-
addVector
private void addVector(FlexBuffersBuilder builder, java.lang.String vectorKey, java.util.List<java.lang.Object> list)
-
convertToEntityProperty
public java.lang.Object convertToEntityProperty(byte[] databaseValue)
- Specified by:
convertToEntityPropertyin interfacePropertyConverter<java.lang.Object,byte[]>
-
convertToKey
java.lang.Object convertToKey(java.lang.String keyValue)
Converts a FlexBuffers string map key to the Java map key (e.g. String to Integer).This required conversion restricts all keys (root and embedded maps) to the same type.
-
shouldRestoreAsLong
protected boolean shouldRestoreAsLong(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.
-
buildMap
private java.util.Map<java.lang.Object,java.lang.Object> buildMap(FlexBuffers.Map map)
-
buildList
private java.util.List<java.lang.Object> buildList(FlexBuffers.Vector vector)
-
-