问题
I would like to use the default LibGDX Json deserializer to read in a JSON file, but implement my own method for writing the class back out to a JSON file. When I implement Json.Serializable, it forces me to implement both the read and write methods. How can I call the default deserializer in the read method?
回答1:
I was looking for the same thing, finally this implemented read method worked for me, I hope it works for you too:
@Override
public void read(Json json, JsonValue jsonMap) {
json.readFields(this, jsonMap);
}
回答2:
You still can make your class implment Json.Serializable. Leave the write method of your serializer blank and implement the read method as you wish. If you are not going to use it, there is nothing wrong with leaving it blank except.
来源:https://stackoverflow.com/questions/27036975/how-to-implement-libgdx-json-serializable-with-default-reader-and-custom-writer