|
| 1 | +package com.arangodb.serde; |
| 2 | + |
| 3 | +import java.lang.reflect.Type; |
| 4 | + |
| 5 | +/** |
| 6 | + * Contract for serialization/deserialization of user data. |
| 7 | + * Implementations of this interface could be used for customizing serialization/deserialization of user related data |
| 8 | + * using serialization/deserialization libraries other than Jackson Databind, like: |
| 9 | + * - serialization libraries for specific JVM languages (e.g. Scala, Kotlin, ...) |
| 10 | + * - serialization libraries already in use in frameworks (e.g. JSON-B, Micronaut Serialization, ...) |
| 11 | + * - high performance serialization libraries (e.g. supporting compile-time databinding code generation) |
| 12 | + * - lower level libraries without support to data binding |
| 13 | + * <p> |
| 14 | + * This interface should not be implemented as an adapter to Jackson Databind, since already existing implementations |
| 15 | + * can be instantiated providing a custom configured Jackson ObjectMapper, see {@link JsonSerde#...} and {@link VPackSerde#...}. |
| 16 | + */ |
| 17 | +public interface ArangoSerde { |
| 18 | + |
| 19 | + /** |
| 20 | + * @return the data type supported by this implementation |
| 21 | + */ |
| 22 | + DataType getDataType(); |
| 23 | + |
| 24 | + /** |
| 25 | + * Serializes the object into the target data type. For data type {@link DataType#JSON}, the serialized JSON string |
| 26 | + * must be encoded into a byte array using the UTF-8 charset. |
| 27 | + * |
| 28 | + * @param value object to serialize |
| 29 | + * @return serialized byte array |
| 30 | + */ |
| 31 | + byte[] serialize(Object value); |
| 32 | + |
| 33 | + /** |
| 34 | + * Deserializes the content and binds it to the target data type. |
| 35 | + * For data type {@link DataType#JSON}, the byte array is the JSON string encoded using the UTF-8 charset. |
| 36 | + * |
| 37 | + * @param content byte array to deserialize |
| 38 | + * @param clazz class of target data type |
| 39 | + * @return deserialized object |
| 40 | + */ |
| 41 | + default <T> T deserialize(byte[] content, Class<T> clazz) { |
| 42 | + return deserialize(content, (Type) clazz); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Deserializes the content and binds it to the target data type. |
| 47 | + * For data type {@link DataType#JSON}, the byte array is the JSON string encoded using the UTF-8 charset. |
| 48 | + * |
| 49 | + * @param content byte array to deserialize |
| 50 | + * @param type target data type |
| 51 | + * @return deserialized object |
| 52 | + */ |
| 53 | + <T> T deserialize(byte[] content, Type type); |
| 54 | + |
| 55 | +} |
0 commit comments