Skip to content
Advertisement

Jackson: Deserialize BigDecimal as plain String using annotation

I have this REST response:

{
    //more fields...
    prevValue: 10104401
}

And this POJO:

public class Parameter {

    //More fields...

    private String prevValue;

    //Getters and setters

}

I’m using Spring RestTemplate with MappingJackson2HttpMessageConverter. With response above, prevValue is deserialized as a String like 1.0104401E7, in scientific notation.

I want it to be deserialized without scientific notation. Is there a way to do this using Jackson annotations?

Advertisement

Answer

You can use the @JsonFormat annotation:

public class Parameter {

    //More fields...

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private String prevValue;

    //Getters and setters

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