我使用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