0

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?

2 Answers 2

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);
}
0

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.

3
  • I'm actually trying to implement the write method and leave the read method as default. I tried leaving the read method blank, but then it doesn't actually read anything in. Nov 20, 2014 at 15:15
  • How do you read and write right now, without using the serializer mentioned?
    – Seyf
    Nov 20, 2014 at 15:29
  • Which serializer? The default serializer or the custom one I wrote? When I don't implement the Json.Serializable interface for the class, the default reader and writer work perfectly fine, except the writer outputs too many variables that aren't really needed for instantiation of the object. My current implementation of the Json.Serializable interface also works fine for both the read and write methods, except I'm a little lazy and would prefer to use the default reader instead, since it does everything I need without having to manually read and check every Json entry. Nov 20, 2014 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.