Why does Java truncate the preceding is in JSON responses?

A Segun :

I have a spring rest API that returns a JSON response from the response class shown below:

public class myResponse {

private String anyString;
private boolean isBoolean;

//getters and setters
}

I am expecting the JSON response to be:

{
"anyString" : "foo",
"isBoolean" : true
}

However, whenever I inspect the browser for the response obtained, I get:

{
"anyString" : "foo",
"boolean" : true
}

Why is the preceding "is" being truncated?

Антон Ткаченко :

If you're using Spring Boot, then somewhere internally it uses Jackson to transform your object into json string.

you can dive into the logic of ObjectMapper class, but the idea is that it follows JavaBeans convention for accessing fields and getting resulting naming.

So, for boolean property named 'isSth' (via method object.isSth() ) actually represents a field 'sth' for json. If you want to strictly set the name of the field in json, use @JsonProperty annotation

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=421600&siteId=1