Skip to main content



      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 11:58
Eclipse UserFriend
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: Tue Jul 15 14:07:35 EDT 2025

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

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

Back to the top