Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to round-trip Enums within Map. #138

Open
rlubke opened this issue Jun 14, 2018 · 1 comment
Open

Unable to round-trip Enums within Map. #138

rlubke opened this issue Jun 14, 2018 · 1 comment

Comments

@rlubke
Copy link

rlubke commented Jun 14, 2018

Consider the following:

@Test
  public void testDeserializationOfEnumInMap() {
    Genson genson = new GensonBuilder().useClassMetadata(true).create();
    Map<String, Object> expected = new LinkedHashMap<>();
    expected.put("minutes", TimeUnit.MINUTES);
    expected.put("seconds", TimeUnit.SECONDS);
    Map result = genson.deserialize(genson.serialize(expected), LinkedHashMap.class);
    assertEquals(expected, result);
  }

The equality failure is due to the value within the deserialized result is String vs TimeUnit.

@EugenCepoi
Copy link
Contributor

Currently class metadata is being used only for datastructures that are being serialized as a json object. The enum isn't this is why there is no way for Genson to know what the type is when deserializing it back.

I started working some time ago to support class metadata for any type, but this has downsides as the generated json becomes more and more of a ad hoc protocol that wouldn't be friendly to consume by other libs/languages. So I did put it on hold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants