JiBX defines a default set of formats used for converting property values to and from text strings. These format definitions are effectively defined in a context outside the root binding element of the binding definition. Most of the conversions are based on the W3C XML Schema datatype definitions, but do differ from the standard schema definitions in that leading and trailing whitespace characters are not stripped from values (meaning the default conversions will report errors for valid schema values in cases where leading or trailing whitespace is used). If this causes problems for your data, the best solution for now is to define custom conversions which strip the leading and trailing whitespace from values. The default formats for simple values are shown in the following table (also see the Date Time Conversions page, for the standard conversions relating to date/time values).
Type | Format Label | Conversion |
---|---|---|
byte |
byte.default | Converts primitive |
char |
char.default | Converts primitive
|
double |
double.default | Converts primitive |
float |
float.default | Converts primitive |
int |
int.default | Converts primitive |
long |
long.default | Converts primitive |
short |
short.default | Converts primitive |
boolean |
boolean.default | Converts primitive |
byte[] |
byte-array.default | Converts byte arrays to and from the schema base64 representation to allow arbitrary binary data. |
java.lang.String |
String.default | Identity converter for |
org.jibx.runtime.QName |
QName.default | Converter for namespace-qualified names using |
java.lang.Boolean |
Boolean.default | Converter for |
java.lang.Object |
Object.default | Converts any object to a string representation by using the
|
These are the conversions you'll get unless you specify otherwise. If you use
a format element to override one of these defaults you'll still be
able to access the default by using the defined label for that format. Defining
your own custom serialization formats is easy, basically requiring only a pair
of static methods to convert to and from String
representations.
See the format element description for details of
defining your own conversions. The org.jibx.runtime.Utility
class
defines a variety of conversion methods, including those used to implement the
standard conversions listed in the above table, so it's a good starting point
for developing your own variations.
java.math.BigDecimal
is a special case. For 1.3 and 1.4.1 JDKs
the default java.lang.Object
conversion from the above table worked
fine. In the 1.5 JDK Sun made a non-backward-compatible change to the format of
the BigDecimal.toString()
output, which meant that the resulting
text does not always match the decimal schema representation (due to the use
of exponents). Because of this JDK compatibility failure JiBX has an added
optional conversion for BigDecimal
which uses a method added in
1.5 JDK to obtain decimal-compatible output:
Type | Format Label | Conversion |
---|---|---|
java.math.BigDecimal |
BigDecimal.java5 | Converts |
In addition to the conversions listed in the tables, JiBX 1.1 and later support automatic conversion of Java 5 enum values to and from strings.