2

When I make a json request to a spring boot backend, Jackson is automatically converting numbers to strings. Is there a way to prevent that?

For example:

JSON

{
    "numberAsString": 123
}

JAVA

private String numberAsString;

after binding json value to the java field numberAsString is equal to "123". i need to prevent this automatic conversion and need to throw some kind of a exception when this happens.

buræquete
  • 14,226
  • 4
  • 44
  • 89
Vimukthi
  • 846
  • 6
  • 19
  • make clear whether you want to handle exception after getting request or even before getting request?? – ASK Jun 20 '19 at 04:15
  • if java field's data type is String and If request contains an integer value need to throw an exception so that i can handle it using @controllerAdvice – Vimukthi Jun 20 '19 at 04:39
  • did anyone find a way to do so? – kirpt Jan 12 '21 at 09:09
  • I think [this](https://stackoverflow.com/questions/61934109/spring-boot-is-automatically-converting-interger-to-string) post gives answer to respective solution. – Sadaf Zohra Mar 08 '23 at 11:54

0 Answers0