Reputation: 21
I have made a REST API in java and I have the following 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;
}
}
In my API class, I get the data for the above DTO from sql and return the response using the code:
Response com.mmp.rest.AbstractResource.buildResponse(Response<?> response, ResponseMode mode)
The output I get looks like this:
[
{
"type": 1,
"typeName": "New type",
"typeMasterList": [
{
"typeMaster": 0,
"typeMasterName": "Default"
},
{
"typeMaster": 1,
"typemasterName": "Custom"
}
],
"TypeTrue": false,
"TypeSpecial": true
}
]
So my doubts are:
Upvotes: 1
Views: 705
Reputation: 199
The JSON framework renames your primitive variables by removing the 'is' and 'has' word from your variable name. You can add a different name by adding @JsonProperty(value="isTypeSpecial")
This answer is stated in answer 1, it is because of the alphabetical order in a HashMap
Hopefully this answers your questions.
Upvotes: 0
Reputation: 57114
[ ... ]
will keep its order since that is an ordered list / array.is...
is like the get...
for regular getters and is therefore stripped away.Upvotes: 1