Package org.dellroad.stuff.jibx
Class ParseUtil
java.lang.Object
org.dellroad.stuff.jibx.ParseUtil
JiBX parsing utility methods. These methods can be used as JiBX value serializer/deserializer methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleandeserializeBoolean(String string) Boolean parser that allows "yes" and "no" as well as the usual "true", "false", "0", "1".static booleandeserializeBooleanStrictly(String string) Deserialize a boolean strictly, only allowing the valuestrueorfalse.static byte[]deserializeByteArray(String string) Deserialize a byte array usingByteArrayEncoder.static byte[]deserializeByteArrayWithColons(String string) Deserialize a byte array using MAC address notation (colon-separated).static DatedeserializeDate(String date) Deserialize aDatein the format supported byDateEncoder.static DatedeserializeDate(String string, String format) Deserialize aDate.static Inet4AddressdeserializeInet4Address(String string) Deserialize anInet4Address.static int[]deserializeIntArray(String string) Deserialize an array of integers separated by commas and/or whitespace.static StringdeserializeMatching(String regex, String string) JiBXStringdeserializer support method that verifies that the input string matches the given regular expression.static PatterndeserializePattern(String string) Deserialize aPattern.static <T> TdeserializeReference(String string, Class<T> type) Deserialize an object by reference.static SimpleDateFormatdeserializeSimpleDateFormat(String string) Deserialize aSimpleDateFormat.static StringdeserializeString(String string) Deserialize aString, allowing arbitrary characters via backslash escapes.static longdeserializeTimeInterval(String string) Derialize a millisecond-granularity time interval, e.g., "30s", "1d12h", "0.250s", etc.static TimeZonedeserializeTimeZone(String string) Deserialize aTimeZone.static URIdeserializeURI(String string) Deserialize anURI.static UUIDdeserializeUUID(String string) Deserialize aUUID.static DatedeserializeXSDDateTime(String date) Deserialize aDatein XSD dateTime format.static StringJiBXStringdeserializer that normalizes a string as is required by thexsd:tokenXSD type.static StringserializeByteArray(byte[] array) Serialize a byte array usingByteArrayEncoder.static StringserializeByteArrayWithColons(byte[] array) Serialize a byte array using MAC address notation (colon-separated).static StringserializeDate(Date date) Serialize aDatein the format supported byDateEncoder.static StringserializeDate(Date date, String format) Serialize aDate.static StringSerialize anInet4Address.static StringserializeIntArray(int[] array) Serialize an array of integers.static StringserializeReference(Object obj) Serialize an object by reference.static StringSerialize aSimpleDateFormat.static StringserializeString(String string) Serialize aString.static StringserializeTimeInterval(long value) Serialize a millisecond-granularity time interval, e.g., "30s", "1d12h", "0.250s", etc.static StringserializeTimeZone(TimeZone timeZone) Serialize aTimeZone.static StringserializeXSDDateTime(Date date) Serialize aDateto XSD dateTime format.
-
Method Details
-
deserializeString
Deserialize aString, allowing arbitrary characters via backslash escapes. The string will be decoded byStringEncoder.decode(java.lang.String).- Parameters:
string- XML encoding created byserializeString(java.lang.String)- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeString
Serialize aString. The string will be encoded byStringEncoder.encode(java.lang.String, boolean).- Parameters:
string- value to encode for XML- Returns:
- encoded value
- See Also:
-
deserializeTimeZone
Deserialize aTimeZone.- Parameters:
string- XML encoding created byserializeTimeZone(java.util.TimeZone)- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeTimeZone
Serialize aTimeZone.- Parameters:
timeZone- value to encode for XML- Returns:
- encoded value
- See Also:
-
deserializeURI
Deserialize anURI.Note: there is no need for a custom serializer, as
URI.toString()already does the right thing.- Parameters:
string- XML encoding created byURI.toString()- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails
-
deserializeReference
Deserialize an object by reference.Invoke this method from your own custom deserializer to produce an result of the correct type.
The object must have been unmarshalled already and had its ID registered via
IdMapper.setId(java.lang.Object, java.lang.String).- Type Parameters:
T- expected type- Parameters:
string- XML encoding created byserializeReference(java.lang.Object)type- expected type- Returns:
- decoded value
- Throws:
IllegalArgumentException- ifstringcannot be parsedJiBXParseException- if the reference has not been registered to any object yet (e.g., forward reference)JiBXParseException- if the referenced object is not an instance oftype- See Also:
-
serializeReference
Serialize an object by reference.The object must have been marshalled already and had its ID assigned via
IdMapper.getId(java.lang.Object).- Parameters:
obj- object to encode by reference for XML- Returns:
- encoded reference
- Throws:
IllegalArgumentException- if the object has not been registered yet (e.g., forward reference)- See Also:
-
deserializeUUID
Deserialize aUUID.Note: there is no need for a custom serializer, as
UUID.toString()already does the right thing.- Parameters:
string- XML encoding created byUUID.toString()- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails
-
deserializeTimeInterval
Derialize a millisecond-granularity time interval, e.g., "30s", "1d12h", "0.250s", etc.- Parameters:
string- XML encoding created byserializeTimeInterval(long)- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeTimeInterval
Serialize a millisecond-granularity time interval, e.g., "30s", "1d12h", "0.250s", etc.- Parameters:
value- millisecond value to encode- Returns:
- encoded value
- See Also:
-
deserializeByteArray
Deserialize a byte array usingByteArrayEncoder.- Parameters:
string- XML encoding created byserializeByteArray(byte[])- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeByteArray
Serialize a byte array usingByteArrayEncoder.- Parameters:
array- array to encode- Returns:
- encoded array
- See Also:
-
deserializeByteArrayWithColons
Deserialize a byte array using MAC address notation (colon-separated). Each byte must have two digits.- Parameters:
string- XML encoding created byserializeByteArrayWithColons(byte[])- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeByteArrayWithColons
Serialize a byte array using MAC address notation (colon-separated). Each byte will have two digits.- Parameters:
array- array to encode- Returns:
- encoded array
- See Also:
-
deserializeInet4Address
Deserialize anInet4Address. No DNS name resolution of any kind is performed.- Parameters:
string- XML encoding created byserializeInet4Address(java.net.Inet4Address)- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeInet4Address
Serialize anInet4Address.- Parameters:
addr- address to encode- Returns:
- encoded address
- See Also:
-
deserializeSimpleDateFormat
Deserialize aSimpleDateFormat.- Parameters:
string- XML encoding created byserializeSimpleDateFormat(java.text.SimpleDateFormat)- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeSimpleDateFormat
Serialize aSimpleDateFormat.- Parameters:
format- date format to encode- Returns:
- encoded format
- See Also:
-
deserializeDate
Deserialize aDate. This method can be used as a deserialize support method.- Parameters:
string- XML encoding created byserializeDate(Date, String)format- format forSimpleDateFormat- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeDate
Serialize aDate. This method can be used as a serialize support method.- Parameters:
date- date to serializeformat- format forSimpleDateFormat.- Returns:
- encoded date
- Throws:
JiBXParseException- ifformatis invalid- See Also:
-
deserializeDate
Deserialize aDatein the format supported byDateEncoder.- Parameters:
date- XML encoding created byserializeDate(Date)- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeDate
Serialize aDatein the format supported byDateEncoder.- Parameters:
date- date to encode- Returns:
- encoded date
- See Also:
-
deserializeXSDDateTime
Deserialize aDatein XSD dateTime format.- Parameters:
date- XML encoding created byserializeXSDDateTime(java.util.Date)- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeXSDDateTime
Serialize aDateto XSD dateTime format.- Parameters:
date- date to encode- Returns:
- encoded date
- See Also:
-
deserializePattern
Deserialize aPattern.Note: there is no need for a custom serializer, as
Pattern.toString()already does the right thing.- Parameters:
string- XML encoding created byPattern.toString()- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails
-
normalize
JiBXStringdeserializer that normalizes a string as is required by thexsd:tokenXSD type. This removes leading and trailing whitespace, and collapses all interior whitespace down to a single space character.- Parameters:
string- string to normalize- Returns:
- normalized string
- Throws:
NullPointerException- ifstringis null
-
deserializeMatching
JiBXStringdeserializer support method that verifies that the input string matches the given regular expression. This method can be invoked by custom deserializers that supply the regular expression to it.- Parameters:
regex- regular expression pattern which input must matchstring- input string- Returns:
- decoded value
- Throws:
NullPointerException- ifstringofregexis nullJiBXParseException- ifstringdoes not matchregexPatternSyntaxException- ifregexis not a valid regular expression
-
deserializeBoolean
Boolean parser that allows "yes" and "no" as well as the usual "true", "false", "0", "1". Comparisons are case-insensitive.- Parameters:
string- XML encoding of boolean value- Returns:
- decoded value
- Throws:
JiBXParseException- if the value is not recognizable as a boolean- See Also:
-
deserializeBooleanStrictly
Deserialize a boolean strictly, only allowing the valuestrueorfalse.- Parameters:
string- XML encoding created byBoolean.toString(boolean)- Returns:
- decoded value
- Throws:
JiBXParseException- if the parse fails- See Also:
-
deserializeIntArray
Deserialize an array of integers separated by commas and/or whitespace.- Parameters:
string- XML encoding created byserializeIntArray(int[])- Returns:
- decoded integer array
- Throws:
JiBXParseException- if the parse fails- See Also:
-
serializeIntArray
Serialize an array of integers. Example: "1, 2, 3".- Parameters:
array- integer array- Returns:
- string encoding of
array - See Also:
-