How to configure JAXB unmarshaller so it will trim leading and trailing whitespaces from strings?
For instance let's consider a simple binding between a Java bean and XML using JAXB annotations:
@XmlRootElement(name="bean")
class Bean {
@XmlElement(required=true)
String name;
@XmlElement(required=true)
int number;
}
I would like to be able to unmarshal XML given bellow so bean.name does not include starting and trailing whitespaces - is "My name", not "
My name
".
<bean>
<name>
My name
</name>
<number>1</number>
</bean>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…