(email subscribers) In reference to my question on how to declare an array
field within a class defined in the "declare" section of a DRL file (for use
within the Drools Server):
Well, it took me 2 days to figure it out, but here is the current answer. I
ended up just processing things in reverse with XStream to see what it was
expecting. That is, I created a Java tester to manually define my Person
and Hobby classes, and then instantiated a Person object and marshalled it
into JSON with XStream to see what it should look like. I then reversed the
process to unmarshall the JSON back into a Java object to verify that
XStream would parse it correctly. The trick was to specify the nested Hobby
objects correctly. There's no way I could have figured this out without
generating the JSON with XStream FIRST.
DRL:
==============================
package com.foobar
declare Hobby
name: String
desc: String
end
declare Person
name: String
hobbies: java.util.ArrayList
end
rule "Person" dialect "mvel"
when
$p : Person();
then
$p.name = $p.name + " has hobby size of " + $p.hobbies.size();
end
===============================
JSON to be generated from the PHP application:
===============================
{
'insert':
{
'out-identifier':'123',
'object':
{
'com.foobar.Person':
{
"name":"Joe",
"hobbies":
[
{
"com.foobar.Hobby":
[
{"name":"Golf","desc":"Sport #1"},
{"name":"Bowling","desc":"Sport #2"}
]
}
]
}
}
}
}
--
View this message in context:
http://drools.46999.n3.nabble.com/How-to-declare-an-array-attribute-withi...
Sent from the Drools: User forum mailing list archive at
Nabble.com.