After some experimentation, there appears to be no way to configure JAXB to handle primitive chars properly. I'm having a hard time accepting it, though.
I've tried defining an XmlAdaptor
to try and coerce it into a String, but the runtime seems to only accept adapters annotated on Object types, not primitives.
The only workaround I can think of is to mark the char field with @XmlTransient
, and then write getters and setters which get and set the value as a String:
@XmlTransient
char gender = 'M';
@XmlElement(name="gender")
public void setGenderAsString(String gender) {
this.gender = gender.charAt(0);
}
public String getGenderAsString() {
return String.valueOf(gender);
}
Not very nice, I'll grant you, but short of actually changing your char field tobe a String, that's all I have.