In Camel 2.6.0, I have a bean method that (amongst other things) takes an
Integer value from the source message. The element containing the Integer
value may or may not exist within the source document. If I define the
method like this;

public boolean validate(@XPath(value = "//CropYear/text()") Integer
cropYear) throws InvalidParameterException {
...
}

When the element does not exist I get
"org.apache.camel.CamelExecutionException: Exception occurred during
execution on the exchange: Exchange[Message: [#document: null]]". If
however, I explicitly set the resultType on the annotation, like this;

public boolean validate(@XPath(value = "//CropYear/text()", resultType =
Integer.class) Integer cropYear) throws InvalidParameterException {
...
}

When the element doesn't exist, I then get an Integer with a value of 0.

Two questions really; 
a) should I have to explicitly set the resultType, rather than it be
inferred from the data type on the method parameter?
b) is it possible to return a null instead when the element doesn't exist,
as zero could be a valid value?

Cheers, Stu

--
View this message in context: 
http://camel.465427.n5.nabble.com/XPath-for-an-Integer-tp4422095p4422095.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to