我使用JAXB将对象序列化为XML。我想在响应中排除具有默认值的元素。在将对象序列化为JSON时,我在ObjectMapper配置中使用JsonSerialize.Inclusion.NON_DEFAULT来排除默认值。
SerializationConfig sc = objectMapper.getSerializationConfig()
.withSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT);
objectMapper.setSerializationConfig(sc);
我也希望XML响应具有相同的行为。 我怎么能这样做?