0

I am using this Domain Class :

@XmlRootElement(name="Target")
@XmlAccessorType(XmlAccessType.NONE )
class TargetElement {

    static constraints = {
        testPurpose()
    }

    @XmlAttribute(name="TestPurpose")
    String testPurpose

    // instead of bellow in comment use this 
    @XmlElementWrapper(name = "Bag")
    @XmlElement(name="Child")
    List<Child> bag= new ArrayList<Child>()
    // 1..n Child
    static hasMany = [child:Child]
}

If I want to add Child elem, I use

def target = new TargetElement(testPurpose:"TestPurpose")
target.getBag().add(child)
target.save(flush:true)
if (target.hasErrors()){
    println '3 ***********' + target.errors
}

But I get list == null for bag.

Why my list is null? It is working for another project and only name is changing. May be my eyes are missing something...

1 Answer 1

0

For whom who get the same trouble : having @XmlElementWrapper value(bag) to null in my Bootstrap.groovy.I have to declare :

ArrayList<Child> bag = new ArrayList<Child>()
bag.add(child1)
bag.add(child2)
targetElement.getBag().addAll(bag)

also I have met another issue whith GROM lazy loading and JAXB. Check that objects nested are retreived : eg :

static mapping = {
    nested lazy: false
}

Hope this will helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.