开发者

JAXB marshalling is not returning some values for these domain objects

I have a Role domain class, which I have simplified to illustrate the case here:

@XmlRootElement(name="Role")
@XmlAccessorType(XmlAccessType.NONE) 
public class Role implements Comparable
{
    @XmlElement
    String title = ""
}

I have some code to test marshalling this domain class which is :

try {
        employee.getProjects().each{ proj -> 
            println "Project name :" + proj.name
            proj.getRoles().each{

                println ("Role title:" + it.title)
                context = JAXBContext.newInstance(Role.class);
                Marshaller m = context.createMarshaller();
                m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                m.marshal ((Role)it, System.out)

            }
        }

    }catch (JAXBException e){
        e.printStackTrace();
        println(e.getCause())
        println ("Ever getting here?")
    }

As you can see, i have some other classes where this is coming from, Employee hasmany projects, Project hasmany Roles

when I run this method, I am getting the following:

Project name :Project 1
Role title:Software Engineer1
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Role>
    <tit开发者_如何学Pythonle></title>
</Role>
Project name :Project 2
Role title:Software Engineer2
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Role>
    <title></title>
</Role>
Project name :Project 3
Role title:Software Engineer3
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Role>
    <title>Software Engineer3</title>
</Role>

What is going on here? This is driving me nuts that it clearly knows to be marshalling title, and the values are there - I can PRINT them but yet they arent showing up wthi avlues in the XML


It would appear this is a hibernate lazy loading problem. I am trying to figure out how to turn off lazy loading for my whole project in the hibernate grails configuration. Barring that, it appears I should be able to workaround the problem using explicit getters/setters, but that is not very groovy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜