Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » MOXy 2.2.0 and CDATA(Specifying that an XmlElement contains a CDATA section)
MOXy 2.2.0 and CDATA [message #659736] Tue, 15 March 2011 08:43 Go to next message
Kasper Thuno is currently offline Kasper Thuno
Messages: 11
Registered: March 2011
Junior Member
Hey,

I've run into a very specific issue with some XML containing CDATA.

Here's an XML snippet:

...
<metadata>
<param name="metadata.text"><![CDATA["xxx" - xxxxxxx.]]></param>
...
</metadata>
...

Snippet from my annotated PoJo class:

...

@XmlElement(name="metadata.text")
private String metadataText;

...

public String getMetadatatext()
{
return metadataText;
}
@XmlCDATA
public void setMetadatatext(String metadataText)
{
this.metadataText = metadataText;
}

...

When unmarshalling this (using a Binder) I get:

javax.xml.bind.UnmarshalException
- with linked exception:
[java.lang.NullPointerException]
at org.eclipse.persistence.jaxb.JAXBBinder.unmarshal(JAXBBinder .java:100)
at dk.gmcb.config.ConfigElementHelper.doUnMarshalling(ConfigEle mentHelper.java:173)
at dk.gmcb.ssm.tree.node.element.ressource.theme.ThemeNodeEleme nt.loadChildren(ThemeNodeElement.java:90)
at dk.gmcb.ssm.tree.node.ElementTreeNode.refresh(ElementTreeNod e.java:701)
at dk.gmcb.ssm.tree.node.ElementTreeNode.reload(ElementTreeNode .java:677)
at dk.gmcb.ssm.utils.TreeUtils.visitAllChildNodes(TreeUtils.jav a:584)
at dk.gmcb.ssm.utils.TreeUtils.visitAllChildNodes(TreeUtils.jav a:591)
at dk.gmcb.ssm.utils.TreeUtils.visitAllChildNodes(TreeUtils.jav a:591)
at dk.gmcb.ssm.utils.TreeUtils.getAllChildNodes(TreeUtils.java: 563)
at dk.gmcb.ssm.tree.AbstractTree.LoadChildNodes(AbstractTree.ja va:201)
at dk.gmcb.ssm.gui.menu.MainMenu$36.actionPerformed(MainMenu.ja va:1170)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButto n.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractB utton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultBu ttonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel .java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItem UI.java:1223)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased (BasicMenuItemUI.java:1264)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:326 7)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container. java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.j ava:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java: 4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDis patchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispat chThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDis patchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread. java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread. java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:12 2)
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.oxm.record.UnmarshalRecord.startCDAT A(UnmarshalRecord.java:1045)
at org.eclipse.persistence.internal.oxm.record.DOMReader.handle ChildNodes(DOMReader.java:252)
at org.eclipse.persistence.internal.oxm.record.DOMReader.report ElementEvents(DOMReader.java:143)
at org.eclipse.persistence.internal.oxm.record.DOMReader.handle ChildNodes(DOMReader.java:249)
at org.eclipse.persistence.internal.oxm.record.DOMReader.report ElementEvents(DOMReader.java:143)
at org.eclipse.persistence.internal.oxm.record.DOMReader.handle ChildNodes(DOMReader.java:249)
at org.eclipse.persistence.internal.oxm.record.DOMReader.report ElementEvents(DOMReader.java:143)
at org.eclipse.persistence.internal.oxm.record.DOMReader.parse( DOMReader.java:89)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller. unmarshal(SAXUnmarshaller.java:363)
at org.eclipse.persistence.oxm.XMLBinder.unmarshal(XMLBinder.ja va:84)
at org.eclipse.persistence.jaxb.JAXBBinder.unmarshal(JAXBBinder .java:89)
... 37 more


I suspect it would work if my String member's name could be initialized like:

private String metadata.text;

, but Java wont accept that Smile - So what to do?
Re: MOXy 2.2.0 and CDATA [message #660278 is a reply to message #659736] Thu, 17 March 2011 12:18 Go to previous messageGo to next message
Kasper Thuno is currently offline Kasper Thuno
Messages: 11
Registered: March 2011
Junior Member
Noone knows how to handle this? Would really appreciate hints or crazy ideas.

TIA!

/Kasper
Re: MOXy 2.2.0 and CDATA [message #660302 is a reply to message #659736] Thu, 17 March 2011 13:56 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise Doughan
Messages: 163
Registered: July 2009
Senior Member

Hi Kasper,

I noticed a couple of items with your metadata. First off you want to put all your annotations on either the field or the property:

@XmlElement(name="metadata.text")
@XmlCDATA
private String metadataText; 

or

@XmlElement(name="metadata.text")
@XmlCDATA
public String getMetadatatext() {
    return metadataText;
}


Second the element name you are actually mapping to is "param" and not "metadata.text":

@XmlElement(name="param")
@XmlCDATA
public String getMetadatatext() {
    return metadataText;
}


If you want the mapping to be conditional on the "metadata.text" attribute you will be interested in an extension (https://bugs.eclipse.org/339596
) we're working on to our XPath based mapping. It will let you do the following:

@XmlPath(name="param[name='metadata.text']/text()")
@XmlCDATA
public String getMetadatatext() {
    return metadataText;
}


-Blaise
[SOLVED] Re: MOXy 2.2.0 and CDATA [message #660384 is a reply to message #660302] Fri, 18 March 2011 05:13 Go to previous message
Kasper Thuno is currently offline Kasper Thuno
Messages: 11
Registered: March 2011
Junior Member
Hi Blaise,

Thanks for replying, and for pointing out that my mapping was mumbo-jumbo. No wonder I couldn't get that to work.

It works now after mapping to a Param object with the XmlCDATA annotation on the value of the element.

Thanks again.

/Kasper
Previous Topic:Isolated Client Session per Request
Next Topic:@ManyToMany: how include columns from @Embeddable map key in primary keys to avoid duplicate errors
Goto Forum:
  


Current Time: Mon Jul 28 16:33:25 EDT 2014

Powered by FUDForum. Page generated in 0.01853 seconds