I'm creating a REST service in Grails to accept data from a python script. The python script generates an XML representation of the object graph and submits it to the controller. Things work great for my flat objects, but I can't figure out how to handle the case where a domain object contains a Set of children objects. For unrelated reasons, my DOA layer is pure Java JPA.
For example, my domain classes (Leaving out getters/setters/etc):
class Schedule {
String name;
@OneToMany;
HashSet<Step> steps;
}
class Step {
String name;
@ManyToOne;
Schedule schedule;
}
My python script generates XML like the following:
<schedule>
<name>Foo</name>
<steps>
<step>
<name>Bar</name>
</step>
<step>
<name>Blatz</name>
</step>
</steps>
</schedule>
In my controller I have this:
def save = {
def schedInstance = new Schedule(params['schedule'])
...
}
The steps property never gets populated. If I dump params out to a log the steps data is all jammed together (In my example above it would yield steps: "BarBlatz"
I have to be doing something terribly wrong. I would imagine that this is a common task. Everything I've been able to find about nesting objects is related to command objects. I don't want to have to duplicate my domain object code in a command object if I can avoid it.