Skip to content
Advertisement

Post request transform int field to string automatically

I’m doing a dummy app of a hostpital. The problem I’m having is that, I’m trying to verify that when a Patient is created, the fields passed are of the correct type, but whenever I POST an Int in a String field, it doesn’t fail and just transform the Int to String. The field I’m trying to make fail is “surname”, which by the definition of the Patient class, is a String.

If I do this (I pass a number to the “surname” field):

JavaScript

It just transforms 43 into a String by the time its in the Controller method. enter image description here

Here we have the Patient object:

JavaScript

And this is the controller class:

JavaScript

EDIT 1:

Following the “clues” and closing the circle of attention, I tried modifying the ObjectMapper, but my configuration isn’t applying. I’m still getting the error from above.

This is the config class:

JavaScript

Even added the property to the application.yml, but still nothing:

JavaScript

Any help is appreciated. Thx.

Advertisement

Answer

In the end I referred to this post to do a deserializer and a module to just have it along all the program, not just the field I want not to be transformed.

Disable conversion of scalars to strings when deserializing with Jackson

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement