Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » moxy fails to render json, jaxb error thrown(moxy failing to render json, get "Referenced Element not declared" error)
moxy fails to render json, jaxb error thrown [message #1696804] Thu, 28 May 2015 16:14
Michael Vandermillen is currently offline Michael VandermillenFriend
Messages: 1
Registered: May 2015
Junior Member
Using EclipseLink MOXy (2.5) as my jax-rs json and xml provider, I (usually, but not always) get the following error only when rendering json (xml always renders fine)

javax.ws.rs.WebApplicationException: HTTP 500 Internal Server Error
        at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:810)

... <snip> ...
Caused by: javax.xml.bind.JAXBException:
Exception Description: Invalid XmlElementRef on property numberOrCaptionOrTitle on class gov.loc.mods.v3.DetailType. Referenced Element not declared.
 - with linked exception:
[Exception [EclipseLink-50006] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Invalid XmlElementRef on property numberOrCaptionOrTitle on class gov.loc.mods.v3.DetailType. Referenced Element not declared.]


Here is the code from the relevant class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "detailType", propOrder = {
    "numberOrCaptionOrTitle"
})
public class DetailType {

    @XmlElementRefs({
        @XmlElementRef(name = "caption", namespace = "www_loc_gov/mods/v3", type = JAXBElement.class),
        @XmlElementRef(name = "title", namespace = "www_loc_gov/mods/v3", type = JAXBElement.class),
        @XmlElementRef(name = "number", namespace = "www_loc_gov/mods/v3", type = JAXBElement.class)
    })

    protected List<JAXBElement<String>> numberOrCaptionOrTitle;
    @XmlAttribute
    protected String type;
    @XmlAttribute
    @XmlSchemaType(name = "positiveInteger")
    protected BigInteger level;

    /**
     * Gets the value of the numberOrCaptionOrTitle property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the numberOrCaptionOrTitle property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getNumberOrCaptionOrTitle().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link JAXBElement }{@code <}{@link String }{@code >}
     * {@link JAXBElement }{@code <}{@link String }{@code >}
     * {@link JAXBElement }{@code <}{@link String }{@code >}
     * 
     * 
     */

    public List<JAXBElement<String>> getNumberOrCaptionOrTitle() {
        if (numberOrCaptionOrTitle == null) {
            numberOrCaptionOrTitle = new ArrayList<JAXBElement<String>>();
        }
        return this.numberOrCaptionOrTitle;
    }

The ObjecFactory has XmlElementDeclarations for caption, title, number, for example:

    @XmlElementDecl(namespace = "www_loc_gov/mods/v3", name = "caption", scope = DetailType.class)
    public JAXBElement<String> createDetailTypeCaption(String value) {
        return new JAXBElement<String>(_DetailTypeCaption_QNAME, String.class, DetailType.class, value);
    }


I say it fails for json usually; sometimes the json renders just fine when deployed (as a war, to tomcat 7), but I can't detect a pattern.

(FYI, namespace links changed to avoid form error)

Thanks.
Previous Topic:Issue with EclipseLink and union when using hsqldb
Next Topic:Nested REF_CURSOR
Goto Forum:
  


Current Time: Tue Feb 20 00:17:30 GMT 2018

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

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