Вы можете использовать XmlAdapter для управления значениями String:
StringCaseAdapter
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class StringCaseAdapter extends XmlAdapter<String, String> {
@Override
public String unmarshal(String v) throws Exception {
return v.toUpperCase();
}
@Override
public String marshal(String v) throws Exception {
return v.toLowerCase();
}
}
SZM
Вы ссылаетесь на XmlAdapter как:
package test.jaxb;
import java.util.ArrayList;
import javax.xml.bind.annotation.*;
@XmlRootElement
public class SZM {
String field01;
@XmlElement(name="field01")
@XmlJavaTypeAdapter(StringCaseAdapter.class)
public void setField01(String value) {this.field01 = value;}
public String getField01() {return field01;}
@XmlElement
@XmlJavaTypeAdapter(StringCaseAdapter.class)
ArrayList<String>collection01;
}
Input.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<szm>
<collection01>def</collection01>
<collection01>ghi</collection01>
<field01>abc</field01>
</szm>
Демо
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(SZM.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
SZM szm = (SZM) unmarshaller.unmarshal(new File("input.xml"));
System.out.println(szm.getField01());
for(String item : szm.collection01) {
System.out.println(item);
}
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(szm, System.out);
}
}
выход
ABC
DEF
GHI
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<szm>
<collection01>def</collection01>
<collection01>ghi</collection01>
<field01>abc</field01>
</szm>