I’m working on a project with JAXB but I run into a small problem with JAXB and the char datatype.
char gender = 'M';
Translates after marshalling into:
<gender>77</gender>
So I think that char is mapped to integer, but I simply want to map it to a String. How can I do this? Is it even possible?
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
XmlAdaptorto 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:Not very nice, I’ll grant you, but short of actually changing your char field tobe a String, that’s all I have.