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

Support for Map<String, String> in JavaPropsMapper #139

Closed
filiphr opened this issue Jul 6, 2019 · 6 comments
Closed

Support for Map<String, String> in JavaPropsMapper #139

filiphr opened this issue Jul 6, 2019 · 6 comments
Labels
Properties Issue related to (Java) Properties format backend
Milestone

Comments

@filiphr
Copy link

filiphr commented Jul 6, 2019

Currently the JavaPropsMapper can only work with java.util.Properties. It would be good if there is support for using Map<String, String> in addition to java.util.Properties.

Would you be open in accepting a PR that adds this support?

@cowtowncoder
Copy link
Member

I am not sure I understand: Maps are supported as values same as with any ObjectMapper.
JavaPropsMapper only adds couple of convenience methods for specific case of Properties.

@filiphr
Copy link
Author

filiphr commented Jul 19, 2019

What I meant is that if you have:

Properties properties = new Properties();
properties.put("test.key", "Value");

JsonNode jsonNode = new JavaPropsMapper().readPropertiesAs(properties, JsonNode.class);
System.out.println(jsonNode);

you will get

{
  "test": {
    "key": "Value"
  }
}

However, for Map<String, String> you can't. I tried using convertValue but that would lead to

{
  "test.key": "Value"
}

Maybe I should have been more specific. I would like to convert Map<String, String> into JsonNode. And it seems that this is not possible (or at least I don't know how to do it).

@cowtowncoder
Copy link
Member

Ah. I think I understand -- so, to convert from Map where keys have dotted notation into logical structure represented? That makes sense.

Technically should be easy, just need to figure out API: could be readMapAs(...) I suppose, as changing signature of existing method would be risky for transitive dependencies (even if it could be source compatible as Properties implements Map).

@cowtowncoder cowtowncoder added 2.10 Properties Issue related to (Java) Properties format backend labels Jul 19, 2019
@filiphr
Copy link
Author

filiphr commented Jul 19, 2019

Ah. I think I understand -- so, to convert from Map where keys have dotted notation into logical structure represented? That makes sense.

Exactly that.

Properties in the end is a Map. However, I do agree with you, new method readMapAs(...) will work. My initial idea was to have a new method for it.

@cowtowncoder
Copy link
Member

Ok cool. I added this on:

https://github.com/FasterXML/jackson-future-ideas/wiki/Jackson-Work-in-Progress

and hope to get this in 2.10.0.pr2 (and final 2.10.0) if all goes well.

@filiphr
Copy link
Author

filiphr commented Jul 19, 2019

That's awesome. Thank you very much. If you need some help let me know

@cowtowncoder cowtowncoder changed the title Support for Map<String, String> in JavaPropsMapper Support for Map<String, String> in JavaPropsMapper Aug 13, 2019
@cowtowncoder cowtowncoder added this to the 2.10.0.pr2 milestone Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Properties Issue related to (Java) Properties format backend
Projects
None yet
Development

No branches or pull requests

2 participants