-
Notifications
You must be signed in to change notification settings - Fork 20
Jackson marshall ignores @XmlAttribute required = true for a “public final static int” #60
Comments
@redblue36 it would be great to have the example class and simple usage here: while explanation is useful, it is easy to get a particular detail wrong. Just to make sure XML Schema is not used at all; Jackson (and modules) operates only on actual POJO classes. |
@cowtowncoder I've attached a sample JAXB class that was generated from an xml schema -- it represents the aspects of the issue noted in the ticket. It is this JAXB annotated object trying to marshal to JSON text using Jackson. Marshaling code =
This code produces this..
The result expected =
|
package objects.hellotest;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"description"
})
@XmlRootElement(name = "messageARequest")
public class MessageARequest {
protected String description;
@XmlAttribute(name = "theVersion", required = true)
public final static int THE_VERSION = 1;
public String getDescription() {
return description;
}
public void setDescription(String value) {
this.description = value;
}
} |
@redblue36 Ok, should have paid attention to the title. So: You could include |
@cowtowncoder Interested in some insight on the design/technical consideration for static exclusion. I'm a Jackson newbie..but willing to apply some time towards an enhancement proposal if in realm of possibility. I think JAXB sees the "fixed" value as a constant and uses public final static as it's implementation to force/ensure that (with no getter). As a simple aside, it is interesting Moxy can handle this scenario...but since Moxy has other issues for me, more interested in a Jackson solution. Would like to understand if a Jackson enhancement is technically possible and I should dig around in the code. Or go down the path of attempting to customize the JAXB class generation. Thoughts? |
@redblue36 This limitation has been there from the beginning, and my understanding is that most if not all serialization packages would exclude Interesting to learn about this as I was not aware that JAXB would allow annotation of static members this way. I can see how it could be useful, just something that I haven't seen used before. If you wanted to see if it was possible to change property detection to handle removal of |
Project moved to: https://github.com/FasterXML/jackson-modules-base/issues so if follow-up desired (at this point I'd consider it "work as intended although different from JAXB"). |
Experiencing a condition where Jackson's JAXB Annotation-aware marshaling to JSON seems to ignore a "public final static int" annotated using @XmlAttribute(name = "theVersion", required = true) in the Java object. Thought initially that GitHub Issue #47 applied to this problem but doesn't appear to resolve.
Everything else in this Java object marshals out just fine.
Wondering if there is an object mapper config or something else I'm missing.
Additional information:
<xs:attribute name="theVersion" type="xs:int" use="required" fixed="1" />
@XmlAttribute(name = "theVersion", required = true) public final static int THE_VERSION = 1;
The Jackson Object Mapper config options using at the moment =
SerializationFeature WRAP_ROOT_VALUE true
SerializationFeature WRITE_DATES_AS_TIMESTAMPS false
SerializationFeature INDENT_OUTPUT true
The text was updated successfully, but these errors were encountered: