-
-
Save rmannibucau/66907a09c1f062b378e67c7f511425c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface JsonbSerializer<T> { | |
// RMB: serialization side doesn't need any jsonp instance since we can hide them all in the context | |
// better cause: 1. doesnt prevent impl not jsonp based (genson got some optimization incompatible with jsonp IIRC), 2. why should the user potentially mess up or suppose anything about jsonp there? | |
/** | |
* Serializes an object to JSON. | |
* | |
* @param obj object to serialize | |
* @param ctx JSONB mapper context | |
*/ | |
void serialize(T obj, SerializationContext ctx); | |
} | |
public interface JsonbDeserializer<T> { | |
// RMB: same thought, parsing solution is a detail there (see https://fasterxml.github.io/jackson-databind/javadoc/2.4/com/fasterxml/jackson/databind/DeserializationContext.html) | |
/** | |
* Deserialize an object from JSON. | |
* @param ctx Deserialization context | |
* @param rtType type of returned object | |
* @return deserialized instance | |
*/ | |
T deserialize(DeserializationContext ctx, Type rtType); | |
} | |
public interface SerializationContext { | |
// RMB: how to know we are in a list (key is the list and not the instance one). | |
/** | |
* Serializes arbitrary object to JSON in the json tree. | |
* Serializations are not ordered (will ignore JsonbConfig configuration). | |
* | |
* | |
* @param key JSON key name | |
* @param object object to serialize | |
* @param <T> Type of serialized object | |
*/ | |
<T> void serialize(String key, T object); | |
} | |
public interface DeserializationContext { | |
// RMB: here we need to be able to deseialize a sub tree for technical use cases (wrapping). | |
// Note: this can then be used as nested, ie multiple JsonbDeserializer are called on a stack to unwrap multiple times | |
/** | |
* Deserializes JSON stream. | |
* | |
* RMB: Note: being based on JsonParser it is better to respect serialization order for performances reason but not mandatory. | |
* | |
* @param clazz Type to deserialize into. No arg constructor required. | |
* @param <T> Type of class | |
* @return Deserialized instance | |
*/ | |
<T> T deserialize(Class<T> clazz); | |
/** | |
* Deserializes JSON stream. | |
* | |
* @param type Type to deserialize into. No arg constructor required. | |
* @param <T> Type to deserialize into | |
* @return Deserialized instance | |
*/ | |
<T> T deserialize(Type type); | |
/** | |
* Deserializes JSON sub-stream/object. | |
* | |
* @param key json key to read | |
* @param type Type to deserialize into. No arg constructor required. | |
* @param <T> Type to deserialize into | |
* @return Deserialized instance | |
*/ | |
<T> T deserialize(String key, Type type); | |
/** | |
* Deserializes JSON sub-stream/object. | |
* | |
* @param key json key to read | |
* @param type Type to deserialize into. No arg constructor required. | |
* @param <T> Type to deserialize into | |
* @return Deserialized instance | |
*/ | |
<T> T deserialize(String key, Class<T> type); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment