Interface DataTranslator<T>
-
- Type Parameters:
T
- The type of object that this translator can handle
public interface DataTranslator<T>
A compatibility object to translate and translate any type ofObject
that is not aDataSerializable
. Natively,DataView
will attempt to locate aDataTranslator
duringDataView.set(DataQuery, Object)
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default DataView
addTo(T obj, DataView dataView)
Serializes theT
object and applies the provided data to the providedDataView
instead of creating a newDataContainer
, reducing nested information.io.leangen.geantyref.TypeToken<T>
token()
Gets theTypeToken
of this translator.T
translate(DataView view)
Attempts to translate theT
object from the providedDataView
.DataContainer
translate(T obj)
Serializes the provided object to aDataContainer
.
-
-
-
Method Detail
-
token
io.leangen.geantyref.TypeToken<T> token()
Gets theTypeToken
of this translator.- Returns:
- The type token for this translator
- See Also:
TypeToken
-
translate
T translate(DataView view) throws InvalidDataException
Attempts to translate theT
object from the providedDataView
.- Parameters:
view
- The data view to translate the object from- Returns:
- The deserialized object
- Throws:
InvalidDataException
- If the dataview contained invalid data
-
translate
DataContainer translate(T obj) throws InvalidDataException
Serializes the provided object to aDataContainer
.- Parameters:
obj
- The object to translate- Returns:
- The object serialized to a container
- Throws:
InvalidDataException
- If the desired object is not supported for any reason
-
addTo
default DataView addTo(T obj, DataView dataView)
Serializes theT
object and applies the provided data to the providedDataView
instead of creating a newDataContainer
, reducing nested information.- Parameters:
obj
- The object to serializedataView
- The data view to serialize to- Returns:
- The provided data view, for chaining
-
-