Created
February 16, 2016 13:13
-
-
Save JamieAP/3c3dd2ece49bef05b137 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 class JsonDecoder<T> extends MessageToMessageDecoder<String, T> { | |
private static final Gson GSON = new GsonBuilder().create(); | |
private final Class<T> clazz; | |
public JsonDecoder(Class<T> clazz, Class<?>... acceptedMsgTypes) { | |
super(acceptedMsgTypes); | |
this.clazz = checkNotNull(clazz); | |
} | |
@Override | |
public T decode(ChannelHandlerContext ctx, String msg) throws Exception { | |
return GSON.fromJson(msg, clazz); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment