Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Note:</strong> I'm the <a href="http://www.eclipse.org/eclipselink/#moxy" rel="nofollow noreferrer"><strong>EclipseLink MOXy</strong></a> lead and a member of the <a href="http://jcp.org/en/jsr/detail?id=222" rel="nofollow noreferrer"><strong>JAXB (JSR-222)</strong></a> expert group.</p> <h2>TL:DR</h2> <p>You can set the following property to override the <code>value</code> key.</p> <pre><code> props.put(MarshallerProperties.JSON_VALUE_WRAPPER, "arguments"); </code></pre> <hr> <h2>Full Test Case</h2> <p>Below is the full working test case. In addition to setting the property I removed an extra space you had in your control document to get the test to pass.</p> <pre><code>import static org.junit.Assert.assertEquals; import java.io.StringWriter; import java.util.HashMap; import java.util.Map; import javax.xml.bind.*; import javax.xml.bind.annotation.*; import org.eclipse.persistence.jaxb.MarshallerProperties; import org.junit.Test; public class JsonRequestTest { @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public static class Request { String method; @XmlAnyElement(lax = true) Object[] arguments; } // InvocationRequest @Test public void testObjectArray() throws JAXBException { System.setProperty(JAXBContext.class.getName(), "org.eclipse.persistence.jaxb.JAXBContextFactory"); Map&lt;String, Object&gt; props = new HashMap&lt;String, Object&gt;(); props.put("eclipselink.media-type", "application/json"); props.put("eclipselink.json.include-root", false); props.put(MarshallerProperties.JSON_VALUE_WRAPPER, "arguments"); JAXBContext ctx = JAXBContext.newInstance( new Class&lt;?&gt;[] { Request.class }, props); Marshaller m = ctx.createMarshaller(); StringWriter writer = new StringWriter(); Request req = new Request(); req.method = "test"; req.arguments = new Object[] { "a", "b" }; m.marshal(req, writer); assertEquals("{\"method\":\"test\",\"arguments\":[\"a\",\"b\"]}", writer.toString()); } } // class JsonRequestTest </code></pre> <hr> <h2><code>@XmlElementWrapper</code> Issue</h2> <p>I have opened the following bug for the issue with <code>@XmlElementWrapper</code>:</p> <ul> <li><a href="http://bugs.eclipse.org/421977" rel="nofollow noreferrer">http://bugs.eclipse.org/421977</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload