Why integer values are converting into string in json

Viewed 62

There is class called Smets2ConnectionStatusModel

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Smets2ConnectionStatusModel {
    private long timestamp;
    private smHanState smHanState;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class smHanState {
        private String state;
        private String subState;
        private long stateChangeTime;
        private float hanSignalStrength;
        private Integer hanRSSI;
        private Integer hanLQI;
    }
}

In my API I'm passing values in JSON format (hardcoded):

@Timed
@PostMapping(value = "/status")
public void handleSESignalStrength() {
    log.info("Get status");
    String message = "{\"timestamp\":1615978156,\"smHanState\":{\"state\":1,\"subState\":\"lowfreqmode\",\"stateChangeTime\":1615978156,\"hanSignalStrCategory\":\"none\",\"hanRSSI\":0,\"hanLQI\":0}};
}

As I have mentioned, the datatype of state is String, still I'm able to pass an integer value (1). It is converting int to String and accepting it, but vice versa it is not true. Wherever I have mentioned datatype as String, I'm able to pass int values. How to fix it? I need it to throw an error while passing an int value.

0 Answers
Related