spring-projects / spring-projects/spring-data-rest

NPE in PersistentPropertyResourceMapping.isExported using SD MongoDB @DbRef Object [DATAREST-796]

Open
#1,173 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Mark Paluch opened DATAREST-796 and commented

Spring Data Rest with Spring Data MongoDB runs into a NPE when using DbRef on Object properties in the associated class.

Model:

    @Data
    @NoArgsConstructor
    @Document(collection = "model")
    public static class Model {

        @Id
        private ObjectId id;
        private String name;

        @DBRef
        private Set<Post> posts;
    }

    @Data
    @NoArgsConstructor
    @Document(collection = "post")
    public static class Post {

        @Id
        private ObjectId id;

        @DBRef
        private Object owner;
    }

Stack-trace:

java.lang.NullPointerException: null
	at org.springframework.data.rest.core.mapping.PersistentPropertyResourceMapping.isExported(PersistentPropertyResourceMapping.java:84) ~[spring-data-rest-core-2.4.4.RELEASE.jar:na]
	at org.springframework.data.rest.core.mapping.MappingResourceMetadata.isExported(MappingResourceMetadata.java:77) ~[spring-data-rest-core-2.4.4.RELEASE.jar:na]
	at org.springframework.data.rest.webmvc.mapping.AssociationLinks.isLinkableAssociation(AssociationLinks.java:95) ~[spring-data-rest-webmvc-2.4.4.RELEASE.jar:na]
	at org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$AssociationUriResolvingDeserializerModifier.updateBuilder(PersistentEntityJackson2Module.java:339) ~[spring-data-rest-webmvc-2.4.4.RELEASE.jar:na]
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:240) ~[jackson-databind-2.6.5.jar:2.6.5]

Affects: 2.4.4 (Gosling SR4), 2.5 RC1 (Hopper)

Reference URL: https://gist.github.com/mp911de/1edbc0ad7b3ae621cc491ac6f2f2e100

Issue Links:

  • DATAREST-797 NPE in LinkCollectingAssociationHandler.doWithAssociation using SD MongoDB @DbRef Object

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.