Home Fabio Cortesi Stefan Jäger

Welcome to the Joint-Venture Blog from Fabio Cortesi and Stefan Jäger.

 

 
 

 

We use JiBX in our current project and had the problem, that JiBX won’t trim whitespaces automatically. For example, a XML tag like <test> asdf  </test> get’s stored as “ asdf  “ instead of “asdf”.

To solve this problem, we created an user-defined formatter for Strings.

package ch.stefanjaeger.formatter;
public class StringFormatter {
  public static String trimString(String untrimmed) {
    return untrimmed.trim();
  }
}

Now just update the binding file of JiBX and JiBX will trim whitespaces:

<format
deserializer="ch.stefanjaeger.formatter.StringFormatter.trimString"
type="java.lang.String" />

 

 

 

 

 
Leave a comment