【发布时间】:2019-02-21 03:11:57
【问题描述】:
我在 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
}
]
所以我的疑问是:
- 为什么对象列表在响应中排在第三位,即使我已在 DTO 中最后声明它?
- 为什么 isTypeTrue 和 isTypeSpecial 在输出中显示为 TypeTrue 和 TypeSpecial?
- 为什么我先声明了isTypeSpecial,却先出现isTypeTrue,后出现isTypeSpecial?
- 有什么方法可以了解 buildResponse 的工作原理吗?
【问题讨论】: