У меня есть 2 класса моделей с именами masterclient и userexternal
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Entity
@Table(name = "user_external")
public class UserExternalModel extends AuditModel {
@Id
@GeneratedValue(generator = "user_external_generator")
@SequenceGenerator(
name = "user_external_generator",
sequenceName = "user_external_sequence",
initialValue = 1
)
@Column(name = "user_id", nullable = false)
private long userId;
@NotBlank
@Size(min = 1, max = 65)
@Column(name = "name", nullable = false)
private String name;
@NotBlank
@javax.validation.constraints.Email
@Size(min = 1, max = 65)
@Column(name = "email", nullable = false)
private String email;
@Column(name = "active")
private int active;
@Column(name = "inactive_by", nullable = true)
private int inactiveBy;
@Column(name = "phone_number", nullable = true)
@Size(min = 1, max = 15)
private String phoneNumber;
@Column(name = "password", nullable = true)
@Size(min = 1, max = 65)
private String password;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@MapsId("client_id")
@JoinColumn(name = "clientId", referencedColumnName = "client_id")
private MasterClientModel masterClientModel;
private long clientId;
@OneToMany(mappedBy = "userExtModel", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
Set<EngagementUserExtModel> engUserExts = new HashSet<>();
public UserExternalModel() {
}
// Getters and Setters (Omitted for brevity)
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getActive() {
return active;
}
public void setActive(int active) {
this.active = active;
}
public int getInactiveBy() {
return inactiveBy;
}
public void setInactiveBy(int inactiveBy) {
this.inactiveBy = inactiveBy;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public MasterClientModel getMasterClientModel() {
return masterClientModel;
}
public void setMasterClientModel(MasterClientModel masterClientModel) {
this.masterClientModel = masterClientModel;
}
public long getClientId() {
return clientId;
}
public void setClientId(long clientId) {
this.clientId = clientId;
}
}
затем
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Type;
@Entity
@Table(name = "master_client")
public class MasterClientModel extends AuditModel {
@Id
@GeneratedValue(generator = "master_client_generator")
@SequenceGenerator(
name = "master_client_generator",
sequenceName = "master_client_sequence",
initialValue = 1
)
@Column(name = "client_id", nullable = false)
private long clientId;
@Size(min = 1, max = 15)
@Column(name = "npwp", nullable = false)
private String npwp;
@Size(min = 1, max = 65)
@Column(name = "company_name", nullable = false)
private String companyName;
@Lob
@Type(type="org.hibernate.type.BinaryType")
@Column(name = "logo", updatable = true, columnDefinition="image")
private byte[] logo;
@Column(name = "description", nullable = true)
@Size(max = 255)
private String description;
@OneToMany(mappedBy = "masterClientModel", fetch = FetchType.LAZY)
Set<UserExternalModel> userExts = new HashSet<>();
@OneToMany(mappedBy = "masterClientModel", fetch = FetchType.LAZY)
Set<EngagementModel> engagements = new HashSet<>();
// Getters and Setters (Omitted for brevity)
public long getClientId() {
return clientId;
}
public void setClientId(long clientId) {
this.clientId = clientId;
}
public String getNpwp() {
return npwp;
}
public void setNpwp(String npwp) {
this.npwp = npwp;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public byte[] getLogo() {
return logo;
}
public void setLogo(byte[] logo) {
this.logo = logo;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
затем, когда я вызвал свой запрос API на userexternal, получил ответ, как показано ниже:
{
"createdDate": "2020-06-18T08:24:17.263+00:00",
"updatedDate": "2020-06-18T08:24:17.263+00:00",
"userId": 1,
"name": "ZZZZZZZZZZZ",
"email": "aaaa@a.com",
"active": 1,
"inactiveBy": 2,
"phoneNumber": "123123123",
"password": "dualipa",
"masterClientModel": {
"createdDate": "2020-06-16T07:33:35.996+00:00",
"updatedDate": "2020-06-16T07:33:35.996+00:00",
"clientId": 1,
"npwp": "12312312312321",
"companyName": "PT A",
"description": "A",
"hibernateLazyInitializer": {}
},
"clientId": 1
}
Мой вопрос в том, как я могу удалить некоторые свойства в «masterClientModel», такие как npwp, имя компании и т. Д. c, когда я нажимаю внешний запрос API, но оставлять его видимым / включенным при нажатии запроса API от masterclientmodel. Я пробовал с jsonignoreproperties value = "npwp", но это не сработало. Любая помощь будет оценена, спасибо.