私は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
が正しいに変更されます。また
public class PropertyEntity implements Serializable, Cloneable {
...
...
@JsonProperty("isEnable")
private boolean isEnable;
...
...
}
参照:
フィールド上で@JsonProperty( "isEnable")を使用してみてください – Naruto
奇妙です。プロパティのうちの1つだけがそのように振る舞う場合、バグのように見えます。 – dbreaux