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

Nested entities in are not rendered correctly [DATAREST-266]

Open
#647 5 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

Johannes Hiemer opened DATAREST-266 and commented

I have a nested Object in MongoDB which looks as follows:

@Document
public class Entity extends AbstractDocument {
	
	private String name;
	
	private List<SubEntity> subEntities;

This document has the SubEntity:

public class SubEntity {
	
	private String name;
	
	private Units units;

In this SubEntity we have the class Units, which in turn contains the problematic @DBRef annotations, which do not work.

public class Units {
	
	@DBRef
	private Unit unit;
	
	@DBRef
	private Unit divisor;

When storing a new Dataset in MongoDB, the data is saved correctly.

{
    "_id" : ObjectId("5318e2db4d1a10c59b94cfaa"),
    "name" : "1234",
    "subEntities" : [ 
        {
           "name" : "1234"
            "units" : {}
        }, 
        {
            "name" : "1234"
            "units" : {}
        }, 
        {
           "name" : "1234"
            "units" : {
                "unit" : {
                    "$ref" : "unit",
                    "$id" : ObjectId("531825594d1a10c59b94cfa2")
                }
            }
        },

Calling this dataset via SD REST, the @DBRef relation is not rendered.

{
    "name": "1234",
    "subEntities": [
        {
           "name": "1234",
            "units": { }
        },
        {
            "name": "1234",
            "units": { }
        },
        {
            "name": "1234",
            "units": { }
        },

Referenced from: commits https://github.com/spring-projects/spring-data-rest/commit/c7059e06a52f19a328d18bed486f7405176a1fe4

0 votes, 5 watchers

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.