Skip to content

Tag: gson

How to fix this unchecked assignment warning?

I got Warning:(31, 46) Unchecked assignment: ‘java.lang.Class’ to ‘java.lang.Class<? extends PACKAGE_NAME.Block>’ warning on the line blockRta.registerSubtype(c);, but I can’t figure out how to fix that without supressing it. ReflectionHelper.getClasses is a static method t…

Conditionally serialise fields in Gson

I have two classes : Player and Match. Player has two fields, playerId and name while Match contains two Player objects and matchId too. When I serialise Player I do want the id and the name to appear in the JSON, however when I serialise Match I get matchId and Player’s non transient fields and their r…

Sort JsonArray by variable key using GSON

I am trying to sort a JsonArray in Java using GSON, I would like to sort everything inside that array via a variable key, meaning there is a string somewhere containing something that is the key that the object needs to be sorted by. Key Variable: varkey1 So it should go like like: Answer Well, you could just…

How can I prevent gson from converting integers to doubles

I’ve got integers in my json, and I do not want gson to convert them to doubles. The following does not work: The output is not what I want: Is there a way to have Integers instead of Doubles in my Map? Edit: not all my fields are integer. I’ve modified my example accordingly. I’ve read quit…