0

I want to convert uid attribute's value in MyJaxbModel class to uppercase during UnMarshalling. I did write UpperCaseAdapter that does the work for me. However with this approach, application performance is deteriorated to unacceptable level (as there are thousands of XML files unmarshalled to MyJaxbModel). I cannot use String.toUppperCase() in getter /setter as these JAXB models are auto generated from XSD and I dont want to tweak them.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "myJaxbModel")
public class MyJaxbModel
{
    protected String name;

    @XmlJavaTypeAdapter(UpperCaseAdapter.class)
    protected String uid;

    // getters and setters

}

public class UpperCaseAdapter extends XmlAdapter<String, String>
{
    @Override
    public String unmarshal( String value ) throws Exception
    {
        return value.toUpperCase();
    }

    @Override
    public String marshal( String value ) throws Exception
    {
        return value;
    }
}

<!--My XSD makes use of below xjc:javaType definition to auto-configure this-->
<xsd:simpleType name="uidType">
    <xsd:annotation>
        <xsd:appinfo>
            <xjc:javaType name="java.lang.String"
                adapter="jaxb.UpperCaseAdapter" />
        </xsd:appinfo>
    </xsd:annotation>
    <xsd:restriction base="xsd:string" />
</xsd:simpleType>

Expected Input: <myJaxbModel name="abc" uid="xyz" />

Expected Output: myJaxbModel.toString() -> MyJaxbModel[name=abc, uid=XYZ]

Is there a better approach to achieve desired results?

1 Answers1

0

Why didn't you simply parse it to upper case in the getUid() or while setting?

if (uid != null){
   return uid.toUpperCase();
}
...

or

 ...
    if (uid != null){
       this.uir =  uid.toUpperCase();
    }

I think that is the easier and cleanest way to do it...

inigoD
  • 1,681
  • 14
  • 26