MOXy - Json - Remove brackets from collection members [message #1844883] |
Tue, 28 September 2021 15:58 |
Eoin Flood Messages: 1 Registered: September 2021 |
Junior Member |
|
|
I am trying to serialize a generic collection of Objects to json using MOXy
e.g.
@Data
@XmlAccessorType(XmlAccessType.FIELD)
public class Shelter {
@XmlElements({
@XmlElement(name = "dog", type = Dog.class),
@XmlElement(name = "cat", type = Cat.class)
})
Collection<? extends Animal> animals;
}
@Data
@XmlAccessorType(XmlAccessType.FIELD)
public class Cat
extends Animal
{
String name;
}
@Data
@XmlAccessorType(XmlAccessType.FIELD)
public class Dog
extends Animal
{
String name;
}
The problem is that the individual objects in the list are enclosed in brackets [...]
{"dog":[{"name":"Rex"}],"cat":[{"name":"Fifi"}]}
Whereas the api that I am calling requires them to be formatted without the brackets
e.g.
{"dog":{"name":"Rex"},"cat":{"name":"Fifi"}}
Any ideas?
|
|
|
Powered by
FUDForum. Page generated in 0.02068 seconds