question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable the Number to String automatic conversion

See original GitHub issue

By 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:closed
  • Created 8 years ago
  • Reactions:17
  • Comments:23 (10 by maintainers)

github_iconTop GitHub Comments

19reactions
martin-muchacommented, Oct 31, 2018

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?

5reactions
joca-btcommented, Jun 17, 2019

I have similar constraints. Something like ALLOW_COERCION_OF_SCALARS but applied to strings would be great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable the Number to String automatic conversion · Issue #192
I tried to create a custom deserializer, but it seems that the value is already converted as a string when I got to...
Read more >
Prevent automatic String to Integer conversion in Jackson
There is a configuration setting on the ObjectMapper called the MapperFeature.ALLOW_COERCION_OF_SCALARS . If set to false , it will prevent ObjectMapper ...
Read more >
How to prevent or stop converting text string to number in Excel?
Prevent converting text string to number by Format Cells​​ 1. Select the cells you want to enter the text strings, and right click...
Read more >
How to avoid automatic type conversion in JavaScript
A very common problem when people code JavaScript, is that they don't take automatic type conversion into account.
Read more >
Disabling the conversion of numbers into links on mobile ...
On some mobile browsers, any string of digits that looks like a phone number is automatically converted to a link. This can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found