I am using springboot 1.5.4, springfox-swagger2-2.7.0 for for developing a springboot application and swagger for rest api documentation. Swagger documentation and rest api response both are showing all properties of associated objects also I don't want to display the fields.
My entity classes:
@Entity
public class Account {
@Id
@GeneratedValue
private Long accountId;
private String accountUid;
private String accountName;
private String contactPerson;
private String emailId;
@ManyToOne
@JoinColumn(name = "account_type_id")
private AccountType accountType;
// ...setter and getters
}
@Entity
public class AccountType {
@Id
@GeneratedValue
private Long accountTypeId;
private String typeName;
private String description;
private int status;
// setter and getters
}
Model class in swagger documentaion is:
{
"accountId": 0,
"accountName": "string",
"accountUid":"string",
"accountType": {
"accountTypeId": 0,
"description": "string",
"status": 0,
"typeName": "string"
},
"contactPerson": "string",
"emailId": "string"
}
response for get account is:
{
"accountId": 1,
"accountName": "xxxxx",
"contactPerson": "xxxx",
"emailId": "test.abc@abc.com",
"accountType": {
"accountTypeId": 1,
"typeName": "xxxxx",
"description": "xxxxx",
"status": 1
}
}
But in both response and swagger also I don't want to display all properties of account type except id. The output I want is
{
"accountId": 1,
"accountName": "xxxxx",
"contactPerson": "xxxx",
"emailId": "test.abc@abc.com",
"accountType": {
"accountTypeId": 1
}
}
I am not able to find whether the problem is with swagger or spring data JPA.