I recently upgraded my project from Spring boot 1.2.4 to 2.0.0. However, the response I receive from the controller given below, produces an empty json array for the portion that should be mapped to the Set webappLocales in the dto object. I put up some print statements, to check the contents, which are populated correctly. In fact, the inner ProjectDTO which also has some Set fields, which get converted correctly to json array. You can find the a snippet of the output and the respective code below.
DTO
public class WebappDTO {
private long id;
private String name;
private Locale coreLocale;
private Set<WebappLocale> webappLocales;
private List<ProjectDTO> projects;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Locale getCoreLocale() {
return coreLocale;
}
public void setCoreLocale(Locale coreLocale) {
this.coreLocale = coreLocale;
}
public Set<WebappLocale> getWebappLocales() {
return webappLocales;
}
public void setWebappLocales(Set<WebappLocale> webappLocales) {
for (WebappLocale single: webappLocales) {
System.out.println("-----INNER TEST TEST----" + single.getLocale().toString());
}
this.webappLocales = webappLocales;
}
public List<ProjectDTO> getProjects() {
return projects;
}
public void setProjects(List<ProjectDTO> projectdto) {
this.projects = projectdto;
}
}
REST Controller
@ApiOperation(value = "Get webapps for current user")
@RequestMapping(value = "/getAll", method = RequestMethod.GET, produces = {
"application/json" })
@PostFilter("hasPermission(filterObject.getId(), 'com.adobe.onyx.server.model.Webapp', 'read')")
public List<WebappDTO> fetchAll() {
List<ProjectDTO> projectDTO;
Set<ProjectConfig> projects;
List<WebappDTO> webappDTO = new ArrayList<WebappDTO>();
List<Webapp> webapps = getAllWebapps();
for (Webapp w : webapps) {
WebappDTO wdto = new WebappDTO();
wdto.setId(w.getId());
wdto.setName(w.getName());
wdto.setCoreLocale(w.getCoreLocale());
wdto.setWebappLocales(w.getWebappLocales());
projects = w.getProjectConfig();
projectDTO = new ArrayList<ProjectDTO>();
for (ProjectConfig p : projects) {
ProjectDTO pd = new ProjectDTO();
pd.setId(p.getId());
pd.setAlfProject(p.getAlfProject());
pd.setMockBuildAvailable(p.isMockBuildAvailable());
pd.setMockElementOrder(p.getMockElementOrder());
pd.setMockPrefix(p.getMockPrefix());
pd.setMockSuffix(p.getMockSuffix());
pd.setName(p.getName());
pd.setPlaceholderRegex(p.getPlaceholderRegex());
pd.setPostProcessors(p.getPostProcessors());
pd.setProjectStartDate(p.getProjectStartDate());
pd.setJiraIssueTypeId(p.getJiraIssueTypeId());
pd.setJiraPriorityId(p.getJiraPriorityId());
pd.setJiraProjectId(p.getJiraProjectId());
pd.setBugAssignee(p.getBugAssignee());
projectDTO.add(pd);
}
wdto.setProjects(projectDTO);
webappDTO.add(wdto);
Set<WebappLocale> test = wdto.getWebappLocales();
for (WebappLocale single: test) {
System.out.println("-----OUTER TEST TEST----" + single.getLocale().toString());
}
}
return webappDTO;
}
Web App Locale DTO
@Entity
@Table(name = "webapp_locales", uniqueConstraints = {
@UniqueConstraint(columnNames = {
"locale_id", "webapp_id" }) })
@XmlRootElement
public class WebappLocale implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private long id;
@ManyToOne
@XmlTransient
@JsonIgnore
@JoinColumn(name = "locale_id")
private Locale locale;
@ManyToOne
@XmlTransient
@JsonIgnore
@JoinColumn(name = "webapp_id")
private Webapp webapp;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public Webapp getWebapp() {
return webapp;
}
public void setWebapp(Webapp webapp) {
this.webapp = webapp;
}
}