How to configure JAXB so it trims whitespaces by default
问题 I would like to configure JAXB so that it trims whitespaces on all string fields I saw the following answer : How to configure JAXB so it trims whitespaces when unmarshalling tag value? But I do not want to have to annotate all string fields as per the suggested answer @XmlElement(required=true) @XmlJavaTypeAdapter(MyNormalizedStringAdapter.class) String name; Thanks! 回答1: Create a XmlAdapter. package com.foo.bar; public class StringTrimAdapter extends XmlAdapter<String, String> { @Override