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

Allow serialization of Properties with non-String values #2657

Closed
cowtowncoder opened this issue Mar 14, 2020 · 2 comments
Closed

Allow serialization of Properties with non-String values #2657

cowtowncoder opened this issue Mar 14, 2020 · 2 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

(for background, see #2656 and #810)

Currently, code like so:

        Properties properties = new Properties();
        properties.put("key", 1);
        String json = new ObjectMapper().writeValueAsString(properties);

will fail with an exception because all values of Properties are assumed to be of type String.
This is due to typing fix made for #810 which leads to selection of StringSerializer -- reasonable for most cases but not all.

While use of Properties for non-String values seems like a wrong thing to do, maybe we could still support it similar to how coercion of non-String values from JSON content works with Properties (for scalars, at least).

@fan2008shuai
Copy link

Hmmh, Thank you for your reply.
That's tricky. Some old code use Properties like a hash map, put non-string into it, unfortunately Properties#getProperty return String. It is conflictive. Maybe following JDK is a good idea.

@cowtowncoder cowtowncoder added this to the 2.11.0 milestone Mar 26, 2020
@cowtowncoder
Copy link
Member Author

Improved code for 2.11(.0) so that serialization actually succeeds.

@cowtowncoder cowtowncoder removed the 2.11 label Apr 12, 2020
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