morphia: HashMap is not properly decoded

Describe the bug HashMap<UUID, any> objects encode perfectly and are stored in Mongo as expected. When decoding, Morphia will use strings as the key instead of UUIDs, despite there being a UUID Converter.

To Reproduce Steps to reproduce the behavior:

  1. Create a HashMap<UUID, String> and put anything in it.
  2. Save the object using datastore.save(map)
  3. Load the object with Morphia.
  4. Try map.get(uuid). Returns null. Try `map.forEach(uid -> System.out.println(uid.toString())) Generates cast error from string to UUID.

Expected behavior I expected the HashMap to properly load with UUID objects as the key.

** Please complete the following information: **

  • Server Version: 4.0.0
  • Driver Version: 3.12.5
  • Morphia Version: 1.6.0

I cannot use version 2.0.0 as currently Java 8 is required. I see this issue was raised and fixed in 2013, but it appears to not be working.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (13 by maintainers)

Most upvoted comments

OK. I’ll see what I can do to recreate this and see about detecting the UUID type. If it saves, it should load. That seems a reasonable minimum expectation. 😃