我使用SpringMVC 4.2.5,并使一个休息控制器,但响应不是我想要的。 这是细节。 我有一个实体命名propertyEntity
,SpringMVC的响应JSON不正确的布尔属性
public class PropertyEntity implements Serializable, Cloneable {
private static final long serialVersionUID = -7032855749875735832L;
private int id;
private String propertyName;
private boolean isEnable;
private boolean isDimension;
private boolean isMetric;
}
和控制器是:
@Controller
@RequestMapping("/api/v1/properties")
public class PropertyController {
@RequestMapping(method = RequestMethod.GET,
produces = "application/json;charset=utf-8")
@ResponseStatus(HttpStatus.OK)
public @ResponseBody
List<PropertyEntity> getAll() {
return propertyService.getAll();
}
}
当我请求API,其结果是:
[
{
"id": 1,
"propertyName": "money1",
"isEnable": true,
"dimension": false,
"metric": true
},
{
"id": 2,
"propertyName": "money2",
"isEnable": true,
"dimension": false,
"metric": true
}
]
我想要的是:
[
{
"id": 1,
"propertyName": "money1",
"isEnable": true,
"isDimension": false,
"isMetric": true
},
{
"id": 2,
"propertyName": "money2",
"isEnable": true,
"isDimension": false,
"isMetric": true
}
]
意想不到的是: isDimention
更改为dimension
, isMetric
更改为metric
, 但isEnable
是正确的。
尝试在场上使用@JsonProperty(“isEnable”) – Naruto
奇怪。如果只有其中一个属性表现如此,那么这看起来像是一个错误。 – dbreaux