Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove leading/trailing white spaces in JAXB?

Tags:

java

jaxb

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

like image 445
mabuzer Avatar asked Feb 26 '23 22:02

mabuzer


1 Answers

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 ' '.

like image 154
skaffman Avatar answered Mar 02 '23 17:03

skaffman