spring-projects / spring-projects/spring-hateoas
Only the first index of Set is marshalled/unmarshalled while using ResourceSupport
@odrotbohm is already working on this.
Since Jan 13, 2016.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
I have a MenuModel that extends ResourceSupport. The MenuModel inturn contains a Set. The SubMenuModel also extends ResourceSupport.
When I try to marshall / unmarshall the MenuModel, only the first element of the SubMenuModel is attached to the MenuModel and rest of the elements are lost.
Please find below the sample code for recreating the issue,
@JsonInclude(value = Include.NON_NULL)
public class MenuModel extends ResourceSupport implements Serializable{
private static final long serialVersionUID = 1698404814795439732L;
private String name;
private boolean active;
private Set<SubMenuModel> submenus;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<SubMenuModel> getSubmenus() {
return submenus;
}
public void setSubmenus(Set<SubMenuModel> submenus) {
this.submenus = submenus;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
}
@JsonInclude(value=Include.NON_NULL)
public class SubMenuModel extends ResourceSupport implements Serializable {
private static final long serialVersionUID = -4096365611186035173L;
private String name;
private boolean active;
@JsonIgnore
private MenuModel menu;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public MenuModel getMenu() {
return menu;
}
public void setMenu(MenuModel menu) {
this.menu = menu;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
}
I am trying to convert the following json to an Object & vice versa and I could find that the second element is lost,
sample json:
{"name":"Electronics","active":true,"submenus":[{"name":"Mobiles","active":true}, {"name":"Tablets","active":true}]}
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
ObjectMapper objectMapper = new ObjectMapper();
MenuModel menuModel = objectMapper.readValue(new File("E:\\test.json"), MenuModel.class);
String value = objectMapper.writeValueAsString(menuModel);
System.out.println(value);
}
resulting json:
{"name":"Electronics","active":true,"submenus":[{"name":"Mobiles","active":true,"links":[]}],"links":[]}
All the elements are in the SubMenuModel is retained when I remove ResourceSupport.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.