Currently I am working on a school project where I had to build a Game in which a user could customize a deck of Cards and save this to a Database via a REST API. This part I got successfully working, however I decided to save the deck of Cards as a JSON String into my database table. Now I am having issues whilst using Gson to parse the object back to the correct Model as it is expecting a properly typed list as opposed to a Json String.
Does anyone have a good solution to easily parse this object or to extract the deck of cards from the Json String before parsing the rest of the object?
I will provide some example code to show the current structure of my object and Json:
Model to Convert to
public class CharacterModel{
private String characterName;
private int maxHp
private List<BattleCard> cardDeck
public CharacterModel(){}
//Getters and Setters for all paramters below
}
Json Format
{
"characterName": "TestCharacter;",
"maxHp": "4",
"cardDeck": "{Json String with the List of Cards here}"
}
What would be the best way to resolve this? As due to the way the JSON String gets nested into the parent JSON String it is not recognized as a object by Gson when trying to convert. Any help with this problem would be very much appreciated.