Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » MOXy - Json - Remove brackets from collection members
MOXy - Json - Remove brackets from collection members [message #1844883] Tue, 28 September 2021 15:58
Eoin Flood is currently offline Eoin FloodFriend
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?

Previous Topic:secure password and user name in persistence.xml
Next Topic:XMLAdapter for list not working
Goto Forum:
  


Current Time: Wed May 25 21:08:57 GMT 2022

Powered by FUDForum. Page generated in 0.01877 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top