Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only the first index of Set is marshalled/unmarshalled while using ResourceSupport #418

Open
jayakumarj85 opened this issue Dec 10, 2015 · 1 comment

Comments

@jayakumarj85
Copy link

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.

@odrotbohm
Copy link
Member

Do you have a sample project that shows that issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants