Skip to main content
formatting
Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

libGDX Json converts Enums to strings and therefore cannot serialize / de-serialize Map keys to anything but strings. 

To fix this, either...

  1. Use strings for keys in Maps (ObjectMap, HashMap ect.).

    Use strings for keys in Maps (ObjectMap, HashMap ect.).

  2. Use GSON which can serialize Enum Map Keys just fine

    Use GSON, which can serialize Enum Map Keys just fine.

  3. Write lost of special serialization / de-serialization code using a class that implements Json.Serializer where T is your map and then register that with your libGDX Json instance .

    Write lots of special serialization / de-serialization code using a class that implements Json.Serializer<T> where T is your map and then register that with your libGDX Json instance.

I recommend option one or two.

libGDX Json converts Enums to strings and therefore cannot serialize / de-serialize Map keys to anything but strings. To fix this either

  1. Use strings for keys in Maps (ObjectMap, HashMap ect.).
  2. Use GSON which can serialize Enum Map Keys just fine
  3. Write lost of special serialization / de-serialization code using a class that implements Json.Serializer where T is your map and then register that with your libGDX Json instance .

I recommend option one or two.

libGDX Json converts Enums to strings and therefore cannot serialize / de-serialize Map keys to anything but strings. 

To fix this, either...

  1. Use strings for keys in Maps (ObjectMap, HashMap ect.).

  2. Use GSON, which can serialize Enum Map Keys just fine.

  3. Write lots of special serialization / de-serialization code using a class that implements Json.Serializer<T> where T is your map and then register that with your libGDX Json instance.

I recommend option one or two.

Source Link

libGDX Json converts Enums to strings and therefore cannot serialize / de-serialize Map keys to anything but strings. To fix this either

  1. Use strings for keys in Maps (ObjectMap, HashMap ect.).
  2. Use GSON which can serialize Enum Map Keys just fine
  3. Write lost of special serialization / de-serialization code using a class that implements Json.Serializer where T is your map and then register that with your libGDX Json instance .

I recommend option one or two.