2

This is my general problem: I want everything to be automated as much as it can be.

This is my specific problem: I want to marshal/unmarshal CDATA. I know that I can specify my own adapter as here. For building process I use Maven and its maven-jaxb2-plugin. Is there some option how to annotate elements in .xsd so they will be automatically annotated by my custom adapter? I really don't want to manually change those after each build.

Any other ways how to solve my problem are more than welcome. :)

EDIT: I've ran to a subproblem and it is described there: JAXB binding - "unable to honor this conversion customization".

Community
  • 1
  • 1
Martin D
  • 667
  • 1
  • 10
  • 25
  • If you have problem about configuration, add some example in order to help you better :) maybe my answer does not complete. – Xstian Aug 06 '14 at 17:46
  • The term "CDATA" means "unparsed character data" and is used to denote a specific representation technique for XML element content: "A CDATA section starts with "<![CDATA[" and ends with "]]>" (w3schools.com) – laune Aug 07 '14 at 05:10
  • have you solved this issue? if yes, how did you solve it? – Xstian Oct 13 '14 at 13:29
  • @Xstian - http://stackoverflow.com/questions/25183594/jaxb-binding-unable-to-honor-this-conversion-customization#comment39356241_25183594 – Martin D Oct 13 '14 at 13:49

1 Answers1

1

try this configuration

<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:annox="http://annox.dev.java.net"
    xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix">
    <bindings schemaLocation="yourXSD.xsd">

            <bindings node="//xsd:complexType[@name='Certificate']//xsd:sequence//xsd:element[@name='certificate']">
                <xjc:javaType name="java.security.cert.X509Certificate" adapter="adapters.X509CertificateAdapter" />
            </bindings>
            <bindings node="//xsd:complexType[@name='User']//xsd:sequence//xsd:element[@name='certificate']">
                <xjc:javaType name="java.security.cert.X509Certificate" adapter="adapters.X509CertificateAdapter" />
            </bindings>

    </bindings>
</bindings>

i solved this issue on this link

this configuration work fine if is an xmltype like xs:string, xs:date, etc.

Try this configuration to solve your problem, using XmlJavaTypeAdapter.

Community
  • 1
  • 1
Xstian
  • 8,184
  • 10
  • 42
  • 72
  • Thank you very much Xstian! It looks that it will do the thing, but I still have a big problem. In my schema, I've declared my own complexType. When I want to bind it, plugin tells me that `...undefined simple type...` – Martin D Aug 07 '14 at 07:59
  • Can you add some configuration or sample? , in order to help you better :) – Xstian Aug 07 '14 at 08:18
  • Sorry, I've edited my comment just after I wrote it to provide source but it somehow didn't save. :) [article-content.xsd](http://pastebin.com/8SUKnDG8), [bindings.xsd](http://pastebin.com/Txpzaqty) – Martin D Aug 07 '14 at 08:27
  • and as a question: http://stackoverflow.com/questions/25183594/jaxb-binding-unable-to-honor-this-conversion-customization – Martin D Aug 07 '14 at 13:18