У меня есть класс
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
@Table(name = "Sheduler")
public @Data class Lesson {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
public int id;
String state;
String goal;
String hobby;
String result;
String interest;
@JsonProperty("fStudentRequest")
boolean fStudentRequest;
@JsonProperty("fTeacherConfirm")
boolean fTeacherConfirm;
@JsonProperty("fStudentConfirm")
boolean fStudentConfirm;
@OneToOne(
cascade = CascadeType.ALL,
orphanRemoval = true,
fetch = FetchType.LAZY
)
@JoinColumn(name = "student_id")
AuthorisedUser student;
@OneToOne(
cascade = CascadeType.ALL,
orphanRemoval = true,
fetch = FetchType.LAZY
)
@JoinColumn(name = "teacher_id")
AuthorisedUser teacher;
@OneToMany(
cascade = CascadeType.ALL,
orphanRemoval = true,
fetch = FetchType.LAZY
)
@JoinColumn(name = "order_id")
List<Robokassa> robokassa = new ArrayList<>();
@OneToMany(
cascade = CascadeType.ALL,
orphanRemoval = true,
fetch = FetchType.EAGER,
mappedBy = "sheduler"
)
List<LessonDays> days = new ArrayList<>();
}
Для сериализации результата я использую дополнительный класс
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.Data;
import play.Logger;
public @Data class HttpJsonResponse<T> {
int status;
String message;
List<T> data = new ArrayList<>();
int code;
public static <T> String createUserResponse(T data,String message,int code,int status){
try {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
HttpJsonResponse<T> response = new HttpJsonResponse<T>();
response.setStatus(status);
response.setCode(code);
response.getData().add(data);
response.setMessage(message);
Logger.debug(mapper.writeValueAsString(response));
return mapper.writeValueAsString(response);
} catch (JsonProcessingException e) {
Logger.error(e.toString());
return "{\"status\":0,\"data\":[],\"code\":\"901\",\"message\":\"error\"}";
}
}
}
Когда я сериализую класс урока, я получаю дублированные поля
String result = HttpJsonResponse
.createUserResponse(
lessons,
"find "+lessons.size(),
CODE_OK,
STAUS_OK
);
Извините за это, но я не могу добавить больше кода в своем посте
{
"status":1,
"message":"find 1",
"data":[
[
{
"id":4565,
"state":"4",
"goal":"4",
"hobby":"hobby",
"result":"result",
"interest":"4",
"student":{
"id":0,
"email":null,
"password":null,
"md5":"e22175516bc91b167e80ceae7276d83b",
"hash":null,
"tags":null,
"emotions":null,
"balance":0.0,
"hibernateLazyInitializer":{
}
},
"teacher":{
"id":0,
"email":null,
"password":null,
"md5":"e22175516bc91b167e80ceae7276d83b",
"hash":null,
"tags":null,
"emotions":null,
"balance":0.0,
"hibernateLazyInitializer":{
}
},
"robokassa":null,
"days":[
{
"id":4558,
"from":"10:00",
"to":"10:45",
"fselect":true,
"fSelect":true
},
{
"id":4559,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4560,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4561,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4562,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4563,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4564,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4566,
"from":"10:00",
"to":"11:00",
"fselect":true,
"fSelect":true
},
{
"id":4567,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4568,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4569,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4570,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4571,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
},
{
"id":4572,
"from":null,
"to":null,
"fselect":false,
"fSelect":false
}
],
"fteacherConfirm":true,
"fstudentConfirm":true,
"fstudentRequest":true,
"fStudentRequest":true,
"fTeacherConfirm":true,
"fStudentConfirm":true
}
]
],
"code":500
}
Что мне нужно сделать, чтобы удалить дубликаты и получить поле типа fStudentConfirm