public class BiDeserializer
extends java.lang.Object
BiSerializer. Provides deserialization
context helpers, withContext(Object, ContextBlock) and getContext().
It is important to understand that each instance has a shared copy of BiMapper to be used in the
deserialization. It is important because there are different mappers for fidderent occasions, for example DefaultBiMapper and BossBiMapper.
| Modifier and Type | Class and Description |
|---|---|
static interface |
BiDeserializer.ContextBlock<E extends java.lang.Throwable>
A lambda to call with context, could throw an exception of set type.
|
| Constructor and Description |
|---|
BiDeserializer()
Construct deserializer with
DefaultBiMapper |
BiDeserializer(BiMapper mapper)
Construct deserializer for a given class mapper
|
| Modifier and Type | Method and Description |
|---|---|
<T,U> T |
deserialize(U object)
Deserialize some object if need.
|
<T> java.util.List<T> |
deserializeCollection(java.util.Collection<?> collection)
Deserialize a collection.
|
void |
deserializeInPlace(java.util.Map map)
Modify a map by deserializing it's values in place.
|
<T> T |
getContext()
Get the current context, if any.
|
<T> T |
getContextOrThrow()
Get context or throw exception if none is set.
|
<T,E extends java.lang.Throwable> |
withContext(T contextValue,
BiDeserializer.ContextBlock<E> block)
Set the deserilaziation context and executes the
BiDeserializer.ContextBlock.perform(). |
public BiDeserializer(BiMapper mapper)
mapper - public BiDeserializer()
DefaultBiMapperpublic <T,U> T deserialize(U object)
BiMapper.deserializeObject(Object) for detailsT - U - object - to deserializepublic <T> java.util.List<T> deserializeCollection(java.util.Collection<?> collection)
T - collection - public void deserializeInPlace(java.util.Map map)
map - public final <T> T getContext()
withContext(Object, ContextBlock)T - public final <T> T getContextOrThrow()
withContext(Object, ContextBlock) for details.T - java.lang.IllegalArgumentExceptionpublic <T,E extends java.lang.Throwable> void withContext(T contextValue,
BiDeserializer.ContextBlock<E> block)
throws E extends java.lang.Throwable
BiDeserializer.ContextBlock.perform(). Context is any object that will
be retured by the getContext() while executing the block. After this call the context will be resotred
to it's previous state, or set to null if no context was set.
It is safe and even recommended to set different context to simplify deserialization logic.
Any exception of specified class thrown by the block will be retransmitted outside.
T - context typeE - exception type that could be thrown from the blockcontextValue - any object to be a current deserialization contextblock - to perform with that contextE - if the BiDeserializer.ContextBlock.perform() thows it.E extends java.lang.Throwable