I want to save a very complex java object to redis as a value. Therefore I have tried to convert this object to Json (gson lib) but it isn't working for my purpose (see other question: GSON java.lang.IllegalArgumentException: class 'xx' declares multiple JSON fields named 'XX' AND StackOverflowError).
I want to store/serialize this mentioned complex java object of an application to redis as a value and load back later to the complex java object (consindering the following comment: Can Jedis get/set an Java POJO?). It is just for evaluation purpose.
How can I accomplish to store this complex object (preferable with json conversion) to redis and back? Every comment would be helpful
Update1: The converstion to json and back is working, but with futher process in the application the system is raising a java.util.LinkedHashMap incompatible with XXX
.
SuperclassExclusionStrategy ex = new SuperclassExclusionStrategy();
Gson gson = new GsonBuilder().addDeserializationExclusionStrategy(ex).addSerializationExclusionStrategy(ex).create();
String json = gson.toJson(daoResult);
daoResultJson = gson.fromJson(json, JavaObject_DAOListResult.class);
There are some objects in the subclasses, which hasn't been converted back in the original state.
Solved
I have solved my problem in using another lib called json-io
Now I can work perfectly fine with with my object. In Gson there were a lot of null properties whis were missing in the json string. With json-io the null properties were converted as well. Here is the solution:
// convert daoResult to JSON
jsonIO = JsonWriter.objectToJson(daoResult);
// convert stored JSON to daoResult
daoResultJson = (DAOListResult) JsonReader.jsonToJava(jsonIO);