Any one have any ideas on how I can serialize / de-serialize an

ObjectMap<Enum, ObjectMap<String, Object>>(); 

(Object is usually a String Integer or Vector2 ) using libgdx's built in json classes?. On de-serialize the inner ObjectMap, is always null even though the values are written to the json file.

  • \$\begingroup\$ Usually I convert my map to a list of key-value pairs, and serialize that. Have you tried anything similar? \$\endgroup\$
    – DMGregory
    Commented Mar 18, 2020 at 11:40
  • \$\begingroup\$ yes But I really don't know how to properly do that \$\endgroup\$ Commented Mar 18, 2020 at 13:41
  • 1
    \$\begingroup\$ Then show us what you tried, and we can help you with what's next. \$\endgroup\$
    – DMGregory
    Commented Mar 18, 2020 at 13:56
  • \$\begingroup\$ I thought libgx classes were automatically serializable via json. \$\endgroup\$ Commented Mar 18, 2020 at 15:35
  • \$\begingroup\$ had someone have told me libgdx json can't de-serialize Enums I would have solved. this days ago \$\endgroup\$ Commented Mar 21, 2020 at 18:29

1 Answer 1


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.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .