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

Incosistent response [DATAREST-1511]

Open
#1,869 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

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

Description

Petar Tahchiev opened DATAREST-1511 and commented

I'm using spring-data-rest and spring-data-jpa (Moore-SR6) and I have entities with relations between them:

@Entity("cms_page")
class CmsPage {

@ManyToOne
@JoinColumn
CmsPageTemplate masterTemplate;

}

when I invoke this: https://localhost:8112/storefront/rest/cms_page/42224328219693664/masterTemplate

I get this response:

{
  "code" : "basic_two_column_email",
  "createdBy" : "admin",
  "createdDate" : "23-04-2020 14:33:21",
  "id" : "42505802237971072",
  "lastModifiedBy" : "admin",
  "lastModifiedDate" : "23-04-2020 14:33:42",
  "cssClasses" : null,
  "frontendTemplateName" : "/emails/samplestore-b2b/basic_two_column",
  "name" : "Basic two column template",
  "online" : false,
  "style" : null,
  "entityName" : "cms_template",
  "cacheName" : "cms_template",
  "idDiscriminator" : 151,
  "new" : false,
  "_links" : {
    "self" : {
      "href" : "https://localhost:8112/storefront/rest/cms_template/42505802237971072"
    },
    "cms_template" : {
      "href" : "https://localhost:8112/storefront/rest/cms_template/42505802237971072"
    },
    "mirrorSyncStates" : {
      "href" : "https://localhost:8112/storefront/rest/sync_state/search/findBySourceIdEquals?sourceId=42505802237971072"
    },
    "syncStates" : {
      "href" : "https://localhost:8112/storefront/rest/cms_template/42505802237971072/syncStates"
    },
    "cmsSlots" : {
      "href" : "https://localhost:8112/storefront/rest/cms_template/42505802237971072/cmsSlots"
    },
    "catalogVersion" : {
      "href" : "https://localhost:8112/storefront/rest/cms_template/42505802237971072/catalogVersion"
    }
  }
}

However some other entities with the same mapping, for example this call https://localhost:8112/storefront/rest/product/21394623779147616/unitOfMeasurement return this kind of response(notice the extra content):

{
  "content" : {
    "code" : "pieces",
    "createdBy" : "admin",
    "createdDate" : "23-04-2020 14:32:39",
    "id" : "22238934085610704",
    "lastModifiedBy" : "admin",
    "lastModifiedDate" : "23-04-2020 14:32:42",
    "name" : {
      "en" : {
        "value" : "Pieces"
      },
      "bg" : {
        "value" : "Бройки"
      }
    },
    "entityName" : "unit",
    "cacheName" : "unit",
    "idDiscriminator" : 79,
    "new" : false
  },
  "_links" : {
    "self" : {
      "href" : "https://localhost:8112/storefront/rest/unit/22238934085610704"
    },
    "unit" : {
      "href" : "https://localhost:8112/storefront/rest/unit/22238934085610704"
    }
  }
}

After some debugging I found out that the object to serialize one case is a hibernate proxy, and because I have registered this:

Hibernate5Module module = new Hibernate5Module();
module.enable(Hibernate5Module.Feature.FORCE_LAZY_LOADING);
module.disable(Hibernate5Module.Feature.USE_TRANSIENT_ANNOTATION);
objectMapper.registerModule(module);

in one of the cases Jackson is using HibernateProxySerializer which is not of type UnwrappingBeanSerializer. In the other case jackson is using the UnwrappingBeanSerializer so the response is unwrapped.

This makes it hard for me to build a ReactJS application with the provided REST, because I have no guarantee of the response format that will be returned.

Is there a way to unify the response, so that it is always unwrapped, or unwrapped?


No further details from DATAREST-1511

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.