From 88733223c6952302630bf618ee1434fe621afaa9 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 5 Aug 2016 13:57:55 +0200 Subject: [PATCH] Making serializers generic --- .../server/data/LoaderCollectionSerializer.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/io/github/norbipeti/chat/server/data/LoaderCollectionSerializer.java b/src/io/github/norbipeti/chat/server/data/LoaderCollectionSerializer.java index cbab388..6db75ae 100644 --- a/src/io/github/norbipeti/chat/server/data/LoaderCollectionSerializer.java +++ b/src/io/github/norbipeti/chat/server/data/LoaderCollectionSerializer.java @@ -1,6 +1,7 @@ package io.github.norbipeti.chat.server.data; import java.io.IOException; +import java.lang.reflect.Type; import java.util.List; import com.google.gson.Gson; @@ -13,10 +14,11 @@ import com.google.gson.stream.JsonWriter; import io.github.norbipeti.chat.server.db.domain.SavedData; // @SuppressWarnings("rawtypes") -public class LoaderCollectionSerializer extends TypeAdapter> { +public class LoaderCollectionSerializer extends TypeAdapter> { + private static final Type returnType = getReturnType(); @Override - public void write(JsonWriter out, LoaderCollection value) throws IOException { + public void write(JsonWriter out, LoaderCollection value) throws IOException { if (value == null) { out.nullValue(); return; @@ -57,4 +59,12 @@ public class LoaderCollectionSerializer extends TypeAdapter return col; } + private static Type getReturnType() { + try { + return LoaderCollection.class.getDeclaredMethod("get", Integer.class).getGenericReturnType(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } }