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

Cannot Change Default Abstract Type Mapper from LinkedHashMap #700

Closed
wealdtech opened this issue Feb 7, 2015 · 2 comments
Closed

Cannot Change Default Abstract Type Mapper from LinkedHashMap #700

wealdtech opened this issue Feb 7, 2015 · 2 comments
Milestone

Comments

@wealdtech
Copy link

An attempt to change the default abstract type mapper from LinkedHashMap to something else (in this case TreeMap) does not work:

  public static void main(String ... args) throws Exception
  {
    final ObjectMapper mapper = new ObjectMapper();
    final SimpleModule module = new SimpleModule("treemaps", Version.unknownVersion());
    module.addAbstractTypeMapping(Map.class, TreeMap.class);
    mapper.registerModule(module);

    final String ser = "{\"obj\":{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"}}";
    final Map<String, Object> deser = mapper.readValue(ser, new TypeReference<TreeMap<String, Object>>() {});
    System.out.println("Class of deser's nested object is " + deser.get("obj").getClass().getSimpleName());
  }

The output of this is Class of deser's nested object is LinkedHashMap.

This is using version 2.5.0.

@cowtowncoder
Copy link
Member

Thank you for reporting this. Sounds like mapping is only applied to main level of deserialization here.

@cowtowncoder
Copy link
Member

I can reproduce this locally with 2.5.1.

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

1 participant