commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vishal Goenka <>
Subject JXPath - Array/Collection conversion doesn't seem to be working?
Date Thu, 22 Apr 2010 15:26:57 GMT
My JXPath context has a variable that is a HashMap<String, String[]>.

Something like:

Map<String, Object> vars = new HashMap<String, Object>();
Map<String, String[]> query = new HashMap<String, String[]>();
query.put("kw",  new String [] {"books", "music"});
vars.put("query", query);

       JXPathContext ctx = JXPathContext.newContext(vars);

When I evaluate the xpath using getValue('query/kw'), I get a String [] back.

      Object result = ctx.getValue('query/kw');

This is fine so far. However, it breaks if I try to run a string
function on the query/kw. So for instance,

      Object result = ctx.getValue('string(query/kw)');

This returns [Ljava.lang.String;@62cc9d70
This same bug affect all string functions such as translate, substring, etc.

Looking at the code, it seems that the CoreFunctions use
InfoSetUtil.stringValue to convert the result set to String.
My first thought was that using TypeUtils.convert(obj, String.class)
instead might solve this problem ... except that TypeUtils.convert
doesn't do "String.valueOf" if the object couldn't be converted to a
String ... therefore, perhaps InfoSetUtil.stringValue will need to
simply be enhanced to handle arrays and collections.

- Vishal

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message