toedter / spring-hateoas-jsonapi

A JSON:API media type implementation for Spring HATEOAS
Apache License 2.0
106 stars 15 forks source link

Deserialization Relationship null (related to issue #70) #72

Closed G4br131 closed 1 year ago

G4br131 commented 1 year ago

Hi, first for all, sorry for my english.

We are using your library to deserialization a json model that has null value relationships, (code below), a feature that is possible as of the latest version

"relationships": {
    "team": {
      "data": null
    }
}

We got an error (NPE) on method JsonApiEntityModelDeserializer#createRelationship because, according to that case, var "entry" is null. "data" atributte is null so there are no id or type attributes. Maybe is it need to be checked in the code or do we need to do something to prevent the library from trying to parse that case?

Thank you

toedter commented 1 year ago

Thanks for reporting this, I'll take a look at asap. What is your use case for creating an entity that does not belong to a team. Rather than specifying the relationship with "data":null why not delete the relationship part from the body?

G4br131 commented 1 year ago

We wanted to comply with the JSON:API specification which requires that if the relationship (to one) exists and there are no elements within it, the only valid relationship object is "data: null".

We also didn't want to manipulate the json file we received by removing parts of it. We just want to simplify the process of parsing the json file into our entity model by using the library. Another team, from the same project, is responsible for generating the json file.

Maybe for now, we should remove that part of the json file, to move forward with our project.

Thanks for your time.