How to implement LibGDX Json.Serializable with default reader and custom writer

廉价感情. 提交于 2019-12-13 04:44:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!