You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to convert data from MessagePack types to basic Java types (Integer, Double, String and etc.) and back, you need mappers.
The mapper contains a stack of converters.
For each type , the converter is selected according to the following logic:
The mapper chooses the first matching converter from the top of the stack (the one that was added last).
Check that converter is suitable
The source type equals the input type of converter
canConvertValue or canConvertObject((depends on converter type see creating your own converter)) should return true
If this converter is not applicable, the mapper checks the next topmost converter after it.
Note: be careful changing the client mapper, it's used as the default mapper for API(call, space(spaceName).select, ...)
Choosing the target type
If you want to manually choose the target type for a particular field in a tuple, use get{targetTypeName} methods
like getInteger, getString and others. See the entire list in TarantoolTuple interface
assertEquals("Miguel de Cervantes", tuple.getString(3));
assertEquals(1605, tuple.getInteger(4));
Creating your own converter
To create your own converter from Java basic types to MessagePack type you can implement ValueConverter interface and override fromValue, canConvertValue methods.
Let's look at the converter implementation. This is default FloatValue to Float converter (FloatValue is a MessagePack type):
If you need converter which will convert MessagePack type to Java basic type (int, double, String and etc.) you can implement ObjectConverter interface and
override toValue, canConvertObject methods:
Default canConvertObject and canConvertValue implementation always returns true.
If any value of source type can be converted to target type you do not have to implement these methods.
Adding converter to mapper
To add MessagePack type converter to the mapper use method registerValueConverter:
After adding converter to the mapper this converter will have maximum priority
because it will be added to the top of the mapper stack.
Converters for container types (like lists and maps) can use mappers inside too, such converters (and mappers holding them) will be in fact recursive.
Creating your own mapper
If you need to work with a custom structure of the received MessagePack objects, e.g. from a custom Lua method, use the mapper factory: