tag:blogger.com,1999:blog-1710464868724994296.post5628231812113342512..comments2023-06-29T09:48:09.653-04:00Comments on Java XML and JSON Binding: CDATA, CDATA Run, Run Data RunBlaise Doughanhttp://www.blogger.com/profile/02016807982653343777noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-1710464868724994296.post-28893577125881672382013-06-19T15:56:52.136-04:002013-06-19T15:56:52.136-04:00Hi Jonathan,
It appears as though you do not incl...Hi Jonathan,<br /><br />It appears as though you do not included a <i>jaxb.properties</i> file to specify MOXy as the JAXB provider (see: <a href="http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html" rel="nofollow">Specifying EclipseLink MOXy as your JAXB Provider</a>). Below is a link to full example that may help.<br />- <a href="https://github.com/bdoughan/blog20110908" rel="nofollow">https://github.com/bdoughan/blog20110908</a><br /><br />-BlaiseBlaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-25543522435482110002013-06-14T17:08:14.787-04:002013-06-14T17:08:14.787-04:00Thanks for the help! I keep getting the following...Thanks for the help! I keep getting the following exception:<br /><br />javax.xml.bind.JAXBException: property "eclipselink-oxm-xml" is not supported<br /><br />My properties file is setup here:<br />InputStream meta = Thread.currentThread().getContextClassLoader().getResourceAsStream("oxm.xml");<br />Map metadata = new HashMap();<br />metadata.put("eclipselink-oxm-xml", new StreamSource(meta));<br /><br />Any thoughts. I have oxm.xml file in the same directory.<br /> Jonathan Popphttps://www.blogger.com/profile/03791641652778015315noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-54089413959383566892012-11-22T16:51:50.825-05:002012-11-22T16:51:50.825-05:00You should submit a feature request to the Users m...You should submit a feature request to the Users mailing list for the JAXB reference implementation:<br /><br />- <a href="http://java.net/projects/jaxb/lists/" rel="nofollow">http://java.net/projects/jaxb/lists/</a><br /><br />-BlaiseBlaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-26353133409323131892012-11-20T04:06:13.973-05:002012-11-20T04:06:13.973-05:00Anyone knows why standard jaxb doesnt support this...Anyone knows why standard jaxb doesnt support this?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-10832751305653443282012-01-11T09:24:04.888-05:002012-01-11T09:24:04.888-05:00That blog post was very helpful. Thanks.That blog post was very helpful. Thanks.Yannicknoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-1207054376667365622011-10-28T16:41:33.373-04:002011-10-28T16:41:33.373-04:00Hi Alexey,
You could try using @XmlAnyElement wit...Hi Alexey,<br /><br />You could try using @XmlAnyElement with a DomHandler to preserve the XML context as a String. Below is a link to an example:<br />- <a href="http://blog.bdoughan.com/2011/04/xmlanyelement-and-non-dom-properties.html" rel="nofollow">@XmlAnyElement and non-DOM Properties</a><br /><br />-BlaiseBlaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-82160937119234896422011-10-24T14:48:48.952-04:002011-10-24T14:48:48.952-04:00Hi Blaise,
I read an xml that contains html text...Hi Blaise,<br /><br /> I read an xml that contains html text that was supposed to be wrapped in CDATA[[ ]] but it is not (provider's bug). I would still like my jaxb to parse it as CDATA. Do you know a way to disable the html entity parsing for a pojo field?<br /><br />Thanks,<br />AlexeyAlexeyhttps://www.blogger.com/profile/01657787551815538853noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-73357634579158640272011-09-15T17:57:25.018-04:002011-09-15T17:57:25.018-04:00Hi Blaise,
I posted a comment about Cdata not gett...Hi Blaise,<br />I posted a comment about Cdata not getting generated on our build server. It was mainly due to some configuration issue due to which jaxb.properties was not getting pushed to our build correctly. I just found this and it is resolved. Pls. ignore my yesterday's comment. Thanks.<br /><br />-DheeruAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-24218015449161180382011-05-04T04:22:59.182-04:002011-05-04T04:22:59.182-04:00Thank you Blaise, it is really great to hear that....Thank you Blaise, it is really great to hear that.<br />Those forums are bound to get some more passers-by now! great for the community and for aspiring pros like myself.<br />I eventually got it to work, by commenting the addition that my POJO had(the only thing different from what your example contained).<br />I had the @XmlAccessorType(XmlAccessType.FIELD)<br />annotation on it, which caused it not to work.<br />Can you please explain why this was the case, and maybe why I would use this property?avinoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-31264142206918085972011-04-28T13:53:55.443-04:002011-04-28T13:53:55.443-04:00Hi Avi,
"I'm at a javax.xml.bind here......Hi Avi,<br /><br />"I'm at a javax.xml.bind here...", nice :).<br /><br />1. Yes, it is okay to use both @XmlCDATA and @XmlElement on the same field/property.<br /><br />2. The containing elements do not need to be marked as @XmlCDATA.<br /><br />3. It has hard to find the right balance in the documentation. I have tried to aim the blog posts at a level beyond "Hello World", while at the same time focusing on only a few concepts. This material is flowing back into the <a href="http://wiki.eclipse.org/EclipseLink/UserGuide/MOXy" rel="nofollow">EclipseLink MOXy (JAXB) User's Guide</a>. The content has been mostly user driven, so feedback is very appreciated.<br /><br />Agreed there are too many unanswered questions on the forums. I am mainly active on the <a href="http://forums.oracle.com/forums/forum.jspa?forumID=48" rel="nofollow">Oracle (TopLink)</a>, <a href="http://www.eclipse.org/forums/index.php?t=thread&frm_id=111&S=9aa1566984c6020783c45aea440fe1d5" rel="nofollow">Eclipse (EclipseLink)</a>, and <a href="http://stackoverflow.com/users/383861/blaise-doughan" rel="nofollow">Stack Overflow</a> forums. I now have my RSS reader pointed at the <a href="http://www.java.net/forums/glassfish/metro-and-jaxb" rel="nofollow">java.net</a> forum.<br /><br />-BlaiseBlaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-37983698491408020562011-04-27T13:44:24.786-04:002011-04-27T13:44:24.786-04:00Hi Blaise. great blog, I use it a lot. Learned abo...Hi Blaise. great blog, I use it a lot. Learned about JAXB&REST here too and other neat stuff.<br /><br />I'm at a javax.xml.bind here...<br /><br />I have created your Customer class (the @XmlCDATA example using 2.2.0), added it to my model classes, marshaled it and returned it to the browser and everything works, when I hit 'view source' I can see the String is wraped in a CDATA block.<br /><br />however, I could not get it to work with the other model classes in the same package, and wanted to ask the following:<br />1.Is it ok to use both @XmlCDATA and @XmlElement on the same element?<br />2.Do I need to define the containing elements as @XmlCDATA elements too? e.g. if Customer was an element in a Customers @XmlRootElement and Customers had 'plain' JAXB annotations would it still work?<br />3.Is there anywhere at all (I've seen the unofficial tutorial in java.net, the MOXy tutorial in eclipse's website, and the API) where I can get a substantial example for more than a 'hello world' or small out of context examples or tutorial that explains the way EclipseLink MOXy and/or JAXB work?<br /><br />just my 2 cents:<br />I seriously appreciate the effort you guys put in here, but I keep seeing unanswered cries for help everywhere(java .net for instance), a decent amount of confusion on how to use annotation frameworks such as Jersey and MOXy, and a certain unfulfilled need for support. I think ultimately this does not serve the purpose of the open source community, and contributes to already widespread misconceptions about how Java is overly complicated and getting too big to carry itself.<br />I thank you again for the blog and other contributions and am looking forward to your answers.avinoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-68144840723150690812011-02-04T16:36:04.905-05:002011-02-04T16:36:04.905-05:00Hi Erik,
Off hand I'm not sure how to prevent...Hi Erik,<br /><br />Off hand I'm not sure how to prevent "<" from being converted to "<". <a href="http://stackoverflow.com/" rel="nofollow">Stack Overflow</a> may be a good place to get an answer on this one.<br /><br />-BlaiseBlaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-81292704083236544652011-02-02T04:31:40.742-05:002011-02-02T04:31:40.742-05:00Hi Blaise
It seem you could be able to answer the...Hi Blaise<br /><br />It seem you could be able to answer the following question.<br /><br />I have an attribute containing '&lt;' and I want JAXB to unmarshal these. The problem is that I can not define an attribute as CDATA, so when unmarshalled the unmarshaller (JAXB2.0-javax.xml.bind.Unmarshaller) converts the '&lt;' to the one character '<'. But I do not want any charaters to be converted.<br /><br />It works fine when used in tags which can be defined as CDATA.<br /><br />I have tried all sorts of stuff incl. trying with DTD to define an attribute as CDATA but that does not work for the unmarshaller. I also tried setting a '@XmlCDATA' on the getters and setters of my Java class containing the attribute but that does not do the trick either.<br /><br />I keep getting the '&lt;' converted to '<'.<br /><br />Can you help on this?Eriknoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-92074288165542324502010-11-09T07:14:05.994-05:002010-11-09T07:14:05.994-05:00A very simple java code.A very simple java code.anehra63http://webhostingreview.infonoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-69379241853290556712010-08-11T17:08:28.567-04:002010-08-11T17:08:28.567-04:00I suppose it mostly depends on the domain you work...I suppose it mostly depends on the domain you work in. I would then say it is more a matter of completeness.Tednoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-20971489101164029212010-08-11T10:05:02.366-04:002010-08-11T10:05:02.366-04:00Thanks for identifying that issue. I have opened ...Thanks for identifying that issue. I have opened the following bug for it (https://bugs.eclipse.org/322358). Do you see this as a common problem, or more a matter of completeness?Blaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-975154578986669912010-08-10T17:57:44.251-04:002010-08-10T17:57:44.251-04:00If I insert the following line of code in the seco...If I insert the following line of code in the second version of the Demo class at line 26:<br /><br />c.setBio("<![CDATA[]]>");<br /><br />I would expect to get the following output:<br /><br /><c><bio><![CDATA[<![CDATA[]]]]><![CDATA[>]]></bio></c> <br /><br />but I get<br /><br /><c><bio><![CDATA[<![CDATA[]]>]]></bio></c><br /><br />which is not well formed.Tednoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-52644187727801128472010-08-09T11:09:32.532-04:002010-08-09T11:09:32.532-04:00Can you clarify your use case. If I modify the in...Can you clarify your use case. If I modify the input to:<br /><br /><c><bio>Before<![CDATA[<html>...</html>]]>After</bio></c> <br /><br />then I see the following as output:<br /><br /><c><bio><![CDATA[Before<html>...</html>After]]></bio></c>Blaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-11925296729078791302010-08-07T12:40:36.500-04:002010-08-07T12:40:36.500-04:00Thank you, this was very useful !
However, it see...Thank you, this was very useful !<br /><br />However, it seems that if the 'bio' string contains an inner CDATA section, the object will not be properly marshalled by MOXy (the inner CDATA section is not properly escaped). The generated XML is then not valid.<br /><br />Please see "Uses of CDATA sections" at http://en.wikipedia.org/wiki/CDATAAnonymousnoreply@blogger.com