How to configure JAXB so it trims whitespaces by default?

EDIT Do note that if the package level annotation is too expansive for you, you could always apply a XmlJavaTypeAdapter annotation to classes.

Create a XmlAdapter. Package com.foo. Bar; public class StringTrimAdapter extends XmlAdapter { @Override public String unmarshal(String v) throws Exception { if (v == null) return null; return v.trim(); } @Override public String marshal(String v) throws Exception { if (v == null) return null; return v.trim(); } } Create a package-info.

Java file in com.foo.bar. Add the following to the package-info. Java file @XmlJavaTypeAdapter(value=StringTrimAdapter.

Class,type=String. Class) package com.foo. Bar; import javax.xml.bind.annotation.adapters.

XmlJavaTypeAdapter; This will apply StringTrimAdapter to all String fields in com.foo. Bar without any extra annotations. EDIT Do note that if the package level annotation is too expansive for you, you could always apply a @XmlJavaTypeAdapter annotation to classes.

Nice answer - I can't speak to the content, but it's extremely well written. I guess Blaise was out to lunch ;-) – Ed Staub Sep 14 '11 at 17:57 @Ed Staub - :). Sahil beat me to it, I did +1 Sahils answer.

– Blaise Doughan Sep 14 '11 at 18:58 1 I try to answer the easy ones, leaving the toughies to the experts :) – Sahil Muthoo Sep 14 '11 at 19:04.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions