Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Marshal list of objects to json with Moxy 2.7.3 problem

Marshaling a list of objects with Moxy 2.7.3 (and glassfish javax.json 1.1.4) does not work as expected. Only the first object is marshaled as a single object. It woks as expected with Moxy 2.7.2. Is this a bug or my code is not quite right?

With Moxy 2.7.2 the json is

With Moxy 2.7.3 the json is

Root root = new Root();
root.addElement("min", "1");
root.addElement("max", "100");
JsonObjectBuilder builder = Json.createObjectBuilder();
JsonObjectBuilderResult result = new JsonObjectBuilderResult(builder);
JAXBContext jc = JAXBContext.newInstance(root.getClass());
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(root, result);
JsonWriterFactory writerFactory = Json.createWriterFactory(null);
JsonWriter writer = writerFactory.createWriter(System.out);

// Root class:
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
public class Root {
@XmlElement private List<Element> elements = new ArrayList<>();
public void addElement(String name, String value) {
Element e = new Element();

// Element class:
import javax.xml.bind.annotation.XmlElement;
public class Element {
@XmlElement private String name;
@XmlElement private String value;
public String getName() {
return name;
public void setName(String name) { = name;
public String getValue() {
return value;
public void setValue(String value) {
this.value = value;

Thank you

Back to the top