mabuzer
mabuzer

Reputation: 6717

remove leading/trailing white spaces in JAXB?

How can I remove leading/trailing white space before/while marshalling in JAXB?

Upvotes: 4

Views: 4251

Answers (1)

skaffman
skaffman

Reputation: 403581

You could use CollapsedStringAdapter:

public class MyClass {

   @XmlJavaTypeAdapter(CollapsedStringAdapter.class) 
   private String field;

}

This adapter removes leading and trailing whitespaces, then truncate any sequnce of tab, CR, LF, and SP by a single whitespace character ' '.

Upvotes: 8

Related Questions