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

SerializeAsArray feature does not work if a list contains a single element only if its XML representation has attributes #8

Open
sberyozkin opened this issue May 14, 2015 · 1 comment

Comments

@sberyozkin
Copy link
Contributor

No description provided.

@sberyozkin
Copy link
Contributor Author

@XmlRootElement(name = "apple")
public static class Apple {

private String name;

public Apple() {

}

public Apple(String n)
{ name = n; }

public void setName(String n) { name = n; }

public String getName()
{ return name; }

}

@XmlRootElement(name = "response")
@XmlSeeAlso(
{Apple.class}

)
public static class CRUDResponse {

private int total = 1;
private List entityList;

public CRUDResponse() {

}

public CRUDResponse(T entity)
{ entityList = new ArrayList(); entityList.add(entity); }

public void setEntityList(List list)
{ entityList = list; }

public List getEntityList()
{ return entityList; }

public void setTotal(int num)
{ total = num; }

public int getTotal()
{ return total; }

}

serializing new CRUDResponse(new Apple("golden delicious")) with an array key pointing to 'entity list' and a namespace map being set to

Map<String, String> namespaceMap = new HashMap<String, String>();
namespaceMap.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");

produces :

{"entityList":
{"@xsi.type":"apple","name":"golden delicious"}

,"total":1}

Wrapping a jettison writer with a custom one which blocks the attributes produces the correct output :

{"entityList":[
{"name":"golden delicious"}

],"total":1}

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

No branches or pull requests

1 participant