Property Value Conversion
The JMS specification defines rules for conversion of property
values, so that, for example, a property value of type int can be read as a long:
// Set the property "Age" as an int value
message.setIntProperty("Age", 72);
...
// Read the property "Age" as a long is legal
long age = message.getLongProperty("Age");The conversion rules are fairly simple, as shown in Table C-1. A property value can be set as one primitive
type or String, and read as one of
the other value types.
Table C-1. Property type conversions
Message.set<TYPE>Property() | Message.get<TYPE>Property() |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Each of the accessor methods (get<TYPE>Property()) can throw the
MessageFormatException. The MessageFormatException is thrown by the
accessor methods to indicate that the original type could not be
converted to the type requested. The MessageFormatException might be thrown if, for
example, a JMS client attempted to read a float property as an int.
String values can be converted
to any primitive type, provided the String is formatted correctly:
Message message = topicSession.createMessage(); // Set the property "Weight" as a String value message.setStringProperty("Weight","240.00"); // Set the property "IsProgrammer" as a String value message.setStringProperty("IsProgrammer", ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access