12345678910111213141516171819202122232425262728293031 |
- package holeg.serialize;
- import com.google.gson.Gson;
- import com.google.gson.TypeAdapter;
- import com.google.gson.TypeAdapterFactory;
- import com.google.gson.reflect.TypeToken;
- import com.google.gson.stream.JsonReader;
- import com.google.gson.stream.JsonWriter;
- import java.io.IOException;
- public class PostDeserializeEnabler implements TypeAdapterFactory {
- @Override
- public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
- final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
- return new TypeAdapter<T>() {
- public void write(JsonWriter out, T value) throws IOException {
- delegate.write(out, value);
- }
- public T read(JsonReader in) throws IOException {
- T obj = delegate.read(in);
- if (obj instanceof PostDeserialize post) {
- post.postDeserialize();
- }
- return obj;
- }
- };
- }
- }
|