我已经用Java制作了REST API,并且具有以下DTO。
@ApiModel(value = "testType", description = "Test type")
public class TestType
{
private int type;
private String typeName;
private boolean isTypeSpecial;
private boolean isTypeTrue;
@JsonInclude(JsonInclude.Include.NON_ABSENT)
private List<typeMasterDTO> typeMasterList;
public TestType()
{
}
@ApiModelProperty(example = "0", value = "Type", required = true)
public int getType()
{
return type;
}
public void setType(int type)
{
this.type= type;
}
@ApiModelProperty(example = "Dragon", value = "Name of the typw", required = true)
public String getTypeName()
{
return typeName;
}
public void setTypeName(String typeName)
{
this.typeName= typeName;
}
@ApiModelProperty(value = "It is a special type", required = true)
public boolean isTypeSpecial()
{
return isTypeSpecial;
}
public void setTypeSpecial(boolean isTypeSpecial)
{
this.isTypeSpecial= isTypeSpecial;
}
@ApiModelProperty(value = "It is a true type", required = true)
public boolean isTypeTrue()
{
return isTypeTrue;
}
public void setTrueType(boolean isTypeTrue)
{
this.isTypeTrue= isTypeTrue;
}
@ApiModelProperty(value = "List of types")
public List<typeMasterDTO> getTypeMasterList()
{
return typeMasterList;
}
public void setTypeMasterList(List<typeMasterDTO> typeMasterList)
{
this.typeMasterList= typeMasterList;
}
}
在我的API类中,我从sql获取上述DTO的数据,并使用以下代码返回响应:
Response com.mmp.rest.AbstractResource.buildResponse(Response<?> response, ResponseMode mode)
我得到的输出看起来像这样:
[
{
"type": 1,
"typeName": "New type",
"typeMasterList": [
{
"typeMaster": 0,
"typeMasterName": "Default"
},
{
"typeMaster": 1,
"typemasterName": "Custom"
}
],
"TypeTrue": false,
"TypeSpecial": true
}
]
所以我的疑问是:
答案 0 :(得分:1)
[ ... ]
中的所有东西都将保持其顺序,因为那是一个有序列表/数组。is...
与常规吸气剂的get...
类似,因此被剥夺了。答案 1 :(得分:0)
JSON框架通过从变量名称中删除“ is”和“ has”字来重命名原始变量。您可以通过添加@JsonProperty(value =“ isTypeSpecial”)
此答案在答案1中有所说明,这是由于HashMap中的字母顺序
希望这能回答您的问题。