I am trying to implement a JsonView to selectively serialize fields from an entity but the json that is serialized has empty objects with no fields. Below is my code:
ViewClass:
public class AuditReportView {
public interface Summary {}
}
Entity:
@Entity
@SequenceGenerator(name = "AUDIT_REPORT_SEQUENCE_GENERATOR", sequenceName = "EJB_AUDIT_REPORT_SEQ", initialValue = 1, allocationSize = 1)
@Table(name = "DEVICE_AUDIT_REPORT")
@Data
public class AuditReport implements Serializable {
private static final long serialVersionUID = 1246376778314918671L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AUDIT_REPORT_SEQUENCE_GENERATOR")
@Column(name = "ID", nullable = false)
@JsonView(AuditReportView.Summary.class)
private Long id;
@Column(name = "DEVICE_ID", nullable = false)
@JsonView(AuditReportView.Summary.class)
private String deviceId;
@Column(name = "REPORT_TIMESTAMP", nullable = false)
@JsonView(AuditReportView.Summary.class)
private Calendar reportTimestamp;
@Column(name = "USER_ID", nullable = false)
@JsonView(AuditReportView.Summary.class)
private long userId;
@Column(name = "USERNAME", nullable = false)
@JsonView(AuditReportView.Summary.class)
private String username;
@Column(name = "START_DATE", nullable = false)
@JsonView(AuditReportView.Summary.class)
private Calendar startDate;
@Column(name = "END_DATE", nullable = false)
@JsonView(AuditReportView.Summary.class)
private Calendar endDate;
@OneToMany(mappedBy = "auditReport", fetch = FetchType.LAZY, orphanRemoval = true, cascade={CascadeType.ALL})
private Set<AuditEntry> auditEntries = new HashSet<AuditEntry>();
}
Controller:
@JsonView(AuditReportView.Summary.class)
@RequestMapping(method = RequestMethod.GET, value = "auditReportSummary")
public @ResponseBody ResponseEntity<?> getAuditReportSummary()
{
final List<AuditReport> auditReports = auditDAO.getAuditReportSummary();
return new ResponseEntity<>(auditReports, HttpStatus.OK);
}
Json from Postman:
[
{},
{},
{}
]
The database only has 3 results and when I debug it is definately pulling them out, it is just that no members are being serialized. I'm using Spring 4.3.7 and Jackson 2.8.7. Any ideas of what could be wrong or where to start debugging the issue?
Thanks