Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DomainClassMarshaller and domain classes with composite key #11450

Closed
dflynn100 opened this issue Dec 12, 2019 · 1 comment · Fixed by grails/grails-plugin-converters#14
Closed
Assignees

Comments

@dflynn100
Copy link

dflynn100 commented Dec 12, 2019

The DomainClassMarshaller in Grails 4.0.1 no longer seems to support rendering JSON from domain objects that map the id attribute to a composite key. Our current thought is that at some point, the DomainClassMarshaller was updated to reference the id attribute of the domain class. Since the id of a composite key is remapped, the DomainClassMarshaller throws a null pointer exception when referencing it.

Note that we are upgrading from 2.5.4, so we don't know when this issue was introduced.

Errors are thrown whether using code such as:

static responseFormats = ['json', 'html']
...
respond myDomainClassWithCompositeKey

or when using a JSON View such as:

model {
    MyDomainClassWithCompositeKey dc
}
json g.render([mydata:dc])

Beginning of stack trace:

java.lang.NullPointerException: null
        at org.grails.web.converters.marshaller.json.DomainClassMarshaller.extractValue(DomainClassMarshaller.java:283)
        at org.grails.web.converters.marshaller.json.DomainClassMarshaller.asShortObject(DomainClassMarshaller.java:264)
        at org.grails.web.converters.marshaller.json.DomainClassMarshaller.marshalObject(DomainClassMarshaller.java:220)
        at org.grails.web.converters.marshaller.json.DomainClassMarshaller.marshalObject(DomainClassMarshaller.java:59)
        at grails.converters.JSON.value(JSON.java:184)
        at grails.converters.JSON.convertAnother(JSON.java:144)
        at org.grails.web.converters.marshaller.json.MapMarshaller.marshalObject(MapMarshaller.java:45)
        at org.grails.web.converters.marshaller.json.MapMarshaller.marshalObject(MapMarshaller.java:30)
        at grails.converters.JSON.value(JSON.java:184)
        at grails.converters.JSON.convertAnother(JSON.java:144)
        at org.grails.web.converters.marshaller.json.CollectionMarshaller.marshalObject(CollectionMarshaller.java:41)
        at org.grails.web.converters.marshaller.json.CollectionMarshaller.marshalObject(CollectionMarshaller.java:30)
        at grails.converters.JSON.value(JSON.java:184)
        at grails.converters.JSON.render(JSON.java:119)
        at org.grails.web.converters.AbstractConverter.writeTo(AbstractConverter.java:110)

Environment: local environment running Docker with latest Ubuntu image, Java 8

@jchharris
Copy link
Contributor

jchharris commented Jan 10, 2020

We have the same issue with rendering the UserRole class from the the SpringSecurityCore plugin.

It works fine in Grails 3.3.11 but is broken in 4.0.1

List<UserRole> roles = UserRole.list()
roles.each { role ->
    println (role as JSON).toString()
}

 java.lang.NullPointerException
            at org.grails.web.converters.marshaller.json.DomainClassMarshaller.marshalObject(DomainClassMarshaller.java:141)
            at org.grails.web.converters.marshaller.json.DomainClassMarshaller.marshalObject(DomainClassMarshaller.java:59)
            at grails.converters.JSON.value(JSON.java:184)
            at grails.converters.JSON.render(JSON.java:119)
            at org.grails.web.converters.AbstractConverter.toString(AbstractConverter.java:118)

 

@davydotcom davydotcom self-assigned this Jun 30, 2020
davydotcom added a commit to davydotcom/grails-plugin-converters that referenced this issue Jul 1, 2020
…entity() property is null for a composite key. This skips the rendering of the identity if it is null. However, it does not render the properties either since they are not considered persistentProperties(). It is recommended to use a custom marshaller as Composite keys, though supported, are not recommmended as per the documentation. Also updated project to gradle 6.5
graemerocher added a commit to grails/grails-plugin-converters that referenced this issue Jul 2, 2020
Partially fixes grails/grails-core#11450 . The PersistentEntity getId…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants