JAXB generating invalid Javadoc - #link byte[] - jaxb

I'm using the maven-jaxb2-plugin to generate JAXB classes from a WSDL file. Unfortunately the automatically generated Javadoc is not Java 8 compliant as it generates the following invalid links:
/**
* Create an instance of {#link JAXBElement }{#code <}{#link byte[]}{#code >}}
*
*/
#XmlElementDecl(namespace = "http://schemas.microsoft.com/2003/10/Serialization/", name = "base64Binary")
public JAXBElement<byte[]> createBase64Binary(byte[] value) {
return new JAXBElement<byte[]>(_Base64Binary_QNAME, byte[].class, null, ((byte[]) value));
}
The #link byte[] reference fails as a missing reference. Unfortunately I don't know if this is being generated by the maven plugin, or JAXB itself.
I don't want to turn of Javadoc linting for my project. Any help on how to fix this without having to resort to adding jxb:javadoc elements all over my WSDL would be appreciated. Thanks

In my case, the erroneous javadoc tags were in the file ObjectFactory.java, and I don't use the ObjectFactory class. So I modified my build script to delete the file after it was generated and before running javadoc.
Cutting the Gordian knot, or using a hammer since it was the only tool I had? You decide.

Related

cxf-codegen-plugin:3.4.2:wsdl2java doesn't produce proper Javadoc

The classes' Javadoc that's produced by cxf-codegen-plugin:3.4.2:wsdl2java looks like the following here:
/**
* <p>Java class for RequestType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="RequestType"&gt;
* &lt;complexContent&gt;
which, of course, is rendered to the following in Eclipse's Javadoc view, for instance:
<p>Java class for RequestType complex type. <p>The following schema fragment specifies the expected content contained within this class. <pre> <complexType name="RequestType"> <complexContent>
Is this a bug in the plugin?
UPDATE
I filed a bug in https://issues.apache.org/jira/browse/CXF-8577.
Comments from https://issues.apache.org/jira/browse/CXF-8577:
This is a known issue fo JAXB 2.3.3, JAXB 2.3.4 has fixed this up.
Please find related discussion here
https://github.com/eclipse-ee4j/jaxb-ri/issues/1471
The released CXF 3.4.4 has already upgraded to use jaxb-xjc 2.3.4, so no such issue with CXF 3.4.4 anymore

How to access/refer/reuse the Odata field as a constant from VDM into another Application specific POJO Classes

We have used cloud SDK(odata-generator-maven-plugin) and generated the VDM out of our EDMX(defined in xml) file. Now, want to refer some of the fields from VDM as a constant in our POJO class instead of re-defining as a constant in our class . I don’t find EDMX field/odataName declared as a variable with public specifier and the constant as well in VDM generated classes.
In the below example,
For example :
VDM snippet - ItemCDSViewForLineItem.java
#ODataField(odataName = "DraftUUID")
private UUID key_2;
public final static ItemCDSViewForLineItemField<UUID> KEY_2 = new ItemCDSViewForLineItemField <UUID>("DraftUUID");
Edmx snippet:
`<Property Name="DraftUUID" Type="Edm.Guid" sap:label="Key"/>`
Is there any way by which I can access or refer “DraftUUID” as a constant field in our own POJO class and reuse it ? Could you please suggest ?
Thanks
Surendra
You need to add Lombok as a dependency to your project to see the public Getters and Setters for these fields. More information can be obtained from the documentation.
To also see them in your IDE you probably need to have a plugin installed as described here.
The method EntityField#getFieldName should give you what you are looking for:
ItemCDSViewForLineItem.KEY_2.getFieldName() // returns "DraftUUID"

xjc mixed content generated as List<Object> instead of List<Serializable>

I am trying to re-generate web service stubs and java objects from WSDL and XSD's using the batch commands available in WAS 7 (wsdl2java.bat, using ant script).
In the generated file, the field denoting mixed content is displayed as:
#XmlMixed
protected List<Object> content;
However, my existing codebase has the following:
#XmlMixed
protected List<Serializable> content;
Due to this issue, I am getting compilation errors. I am using JDK 1.6.
The schema has not change in between. It would be great if you could advise me on how to make sure the generated code confirms to Serializable type instead of object.
Use -extension when generating JAXB classes and check. Like below.
xjc -extension schema.xsd

How to customise the XML output of a Jersey JAXB serialisation

I have some #javax.xml.bind.annotation.Xml... annotated classes here intended for a RESt web service. Jersey is setup in a spring managed web container and the web service is returning a well formatted xml. We use the maven-enunciate-plugin to document the web service and create the xsd to the returned xml documents. I now would like to use the documentation xsd file as a schemaLocation within the returned xml file so that the xml validation won't complain about missing definions. How can I get the XML serialisation configured for this?
If I remember correctly, I had to do a few of things to get namespace identifiers properly written into my generated XML.
1) Created a JaxbFactory that configs and returns a custom marshaller (and unmarshaller, too, BTW). I'm omitting the getters/and unmarshalling setup below...
//constructor
public JaxbFactory() throws Exception {
context = JAXBContext.newInstance(ResourceDto.class);
// Setup the marshaller
marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, XmlMetadataConstants.XML_SCHEMA_LOCATION); // this schema location is used in generating the schema-location property in the xml
}
2) That factory class isn't "visible" to Jersey. To make it visible, I create a MarshallerProvider. That looks something like this:
#Provider
public class ResourceJaxbMarshallerProvider implements ContextResolver<Marshaller> {
// injected by Spring
private ResourceJaxbFactory ResourceJaxbFactory;
private ResourceStatusJaxbFactory ResourceStatusJaxbFactory;
/*
* ----------------------------------------
* Setters (for Spring injected properties)
* ----------------------------------------
*/
public void setResourceJaxbFactory(ResourceJaxbFactory ResourceJaxbFactory) {
this.ResourceJaxbFactory = ResourceJaxbFactory;
}
public void setResourceStatusJaxbFactory(ResourceStatusJaxbFactory ResourceStatusJaxbFactory) {
this.ResourceStatusJaxbFactory = ResourceStatusJaxbFactory;
}
/*
* ------------------------
* Interface Implementation
* ------------------------
*/
public Marshaller getContext(Class<?> type) {
if (type == ResourceDto.class)
return ResourceJaxbFactory.getMarshaller();
else if (type == ResourceStatusDto.class)
return ResourceStatusJaxbFactory.getMarshaller();
else
return null;
}
}
I've got Jersey wired into Spring using the Jersey/Spring Servlet so any #Provider class that gets created by Spring is automatically recognized by Jersey. In my Spring applicationContext.xml all I have to do is instantiate the resource provider. It will, in turn, go grab the marshaller from the factory.
3) The other thing that I found critical was that I had to create a package-info.java file in the root package containing my resource. Looks like this:
/*
* Note that this file is critical for ensuring that our ResourceDto object is
* marshalled/unmarshalled with the correct namespace. Without this, marshalled
* classes produce XML files without a namespace identifier
*/
#XmlSchema(namespace = XmlMetadataConstants.XML_SCHEMA_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED)
package com.yourcompany.resource;
import javax.xml.bind.annotation.XmlNsForm;
At least I think that's everything I needed to do, I can't remember every single piece. I do remember that the package-info.java piece was the last critical cog that made it all come together.
Hope that helps. I spent wayyyy too much time digging for the info on all this. Jersey was seductively simple before I wanted it to do proper xml schema validation (and decent error reporting for schema-invalid input). Once I started down that road Jersey went from brain-dead easy to decently hard. The majority of that difficulty was sussing out all the details from the variety of posts online. Hopefully this will help get you farther, quicker. :-)

JAXB Unable To Handle Attribute with Colon (:) in name?

I am attempting to use JAXB to unmarshall an XML files whose schema is defined by a DTD (ugh!).
The external provider of the DTD has specified one of the element attributes as xml:lang:
<!ATTLIST langSet
id ID #IMPLIED
xml:lang CDATA #REQUIRED
>
This comes into the xjc-generated class (standard generation; no *.xjb magic) as:
#XmlAttribute(name = "xml:lang", required = true)
#XmlJavaTypeAdapter(NormalizedStringAdapter.class)
protected String xmlLang;
However, when unmarshalling valid XML files with JAXB, the xmlLang attribute is always null.
When I edited the XML file, replacing xml:lang with lang and changed the #XmlAttribute to match, unmarshalling was successful (i.e. attributes were non-null).
I did find this http://old.nabble.com/unmarshalling-ignores-element-attribute-%27xml%27-td22558466.html. But, the resolution there was to convert to XML Schema, etc. My strong preference is to go straight from an un-altered DTD (since it is externally provided and defined by an ISO standard).
Is this a JAXB bug? Am I missing something about "namespaces" in attribute names?
FWIW, java -version = "build 1.6.0_20-b02" and xjc -version = "xjc version "JAXB 2.1.10 in JDK 6""
Solved the issue by changing replacing xml: with a namespace declaration in the JAXB-generated class:
#XmlAttribute(name = "lang", namespace="http://www.w3.org/XML/1998/namespace", required = true)
Which makes sense, in a way.
Without this kind of guidance, how would JAXB know how to interpret the otherwise-undefined namespace xml:? Unless, of course, it implemented some special-case internal handling to xml: as done in http://java.sun.com/javase/6/docs/api/javax/xml/stream/XMLStreamReader.html#getNamespaceURI%28java.lang.String%29 (see the first NOTE:)
Whether it's a bug in xjc's generation of the annotated objects or a bug in the unmarhaller, or simply requires a mapping somewhere in the xjc process is still an open question in my mind.
For now, it's working and all it requires is a little xjc magic, so I'm reasonably happy.
Disclaimer: Although 8 years late, I am adding this answer for lost souls such as myself trying to understand auto generation of java files from a DTD.
You can set project wide namespaces for the unmarshaller to work with directly in the project-info.java file via the #XmlSchema option.
This file should be automatically generated by xjc when generating classes from a schema, however it appears xjc does not automatically generate the package-info.java file when generating from a DTD!
However, you can manually make this file, and add it to the same package as the files generated by xjc.
The file would look like the following:
package-info.java :
#XmlSchema(
elementFormDefault=XmlNsForm.QUALIFIED,
xmlns = {
#XmlNs(prefix="xlink", namespaceURI="http://www.w3c.org/1999/xlink"),
#XmlNs(prefix="namespace2", namespaceURI="http://www.w3c.org/1999/namespace2")
})
package your.generated.package.hierarchy;
import javax.xml.bind.annotation.*;
You can add as many namespaces as required, simply add a new line in the form:
#XmlNs(prefix="namespace", namespaceURI="http://www.uri.to.namespace.com")
The benefit of doing it this way, rather than compared to editing the generated #XmlAttribute is that you do not need to change each generated XmlAttribute, and you do not need to manually remove the namespaces from the XmlAttribute name variable.

Resources