Package it.polimi.ingsw.Common
Class GsonOptionalSerializer<T>
java.lang.Object
it.polimi.ingsw.Common.GsonOptionalSerializer<T>
- Type Parameters:
T
- effective type
- All Implemented Interfaces:
com.google.gson.JsonDeserializer<Optional<T>>
,com.google.gson.JsonSerializer<Optional<T>>
public class GsonOptionalSerializer<T>
extends Object
implements com.google.gson.JsonSerializer<Optional<T>>, com.google.gson.JsonDeserializer<Optional<T>>
Correctly manages Optional serialization and deserialization of Optional.empty() values
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
GsonOptionalSerializer
public GsonOptionalSerializer()
-
-
Method Details
-
deserialize
public Optional<T> deserialize(com.google.gson.JsonElement json, Type typeOfT, com.google.gson.JsonDeserializationContext context) throws com.google.gson.JsonParseException - Specified by:
deserialize
in interfacecom.google.gson.JsonDeserializer<T>
- Throws:
com.google.gson.JsonParseException
-
serialize
public com.google.gson.JsonElement serialize(Optional<T> src, Type typeOfSrc, com.google.gson.JsonSerializationContext context) - Specified by:
serialize
in interfacecom.google.gson.JsonSerializer<T>
-