Disable the Number to String automatic conversion
See original GitHub issueBy default, Jackson is converting numbers to strings. In most cases, that’s fine. But not in my situation unfortunately. Is there a way to prevent that?
For example:
JSON
{
"numberAsString": 123
}
JAVA
private String numberAsString;
It works just fine. But the thing is that I want this automatic boxing not enabled and got an exception instead. So the user is forced to use a String. I.e.
{
"numberAsString": "123"
}
I don’t think such a feature exist, I look on http://wiki.fasterxml.com/JacksonFeaturesGenerator and a bit everywhere like http://stackoverflow.com/questions/7806316/jackson-json-converts-integers-into-strings
I tried to create a custom deserializer, but it seems that the value is already converted as a string when I got to the deserializer, and I don’t have the possibility to determine if it was a string or an integer originally in the request.
Thanks
Fabian
Issue Analytics
- State:
- Created 8 years ago
- Reactions:17
- Comments:23 (10 by maintainers)
thanks for this discussion and provided “workaround”. But this should really be DeserializationFeature. Automatic type conversion are evil and as such belongs to javascript. It should have never been on turned on by default, and thus there should be easy way to turn it off at least. It’s kinda weird have to write ForceStringDeserializer into every project. Can someone reconsider adding it?
I have similar constraints. Something like
ALLOW_COERCION_OF_SCALARS
but applied to strings would be great!