jasminb / jsonapi-converter

JSONAPI-Converter is a Java/Android library that provides support for working with JSONAPI spec
Apache License 2.0
272 stars 81 forks source link

Add option to prevent serialization of the data section of a relationship #224

Closed ghost closed 4 years ago

ghost commented 4 years ago

These changes are intended to fix issue #186 (@RelationshipLinks without @Relationship not working). The JSON:API spec does not require that relationship objects contain data. Until now, it was not possible avoid serialization of relationship data even if it will never be populated.

Implementation: I've extended the @Relationship annotation with a new serialiseData field. Existing behavior is retained by default, making this a non-breaking change. Setting serialiseData to false will disable serialization of the data section. It will also prevent generation of included resources for the annotated relationship.

jasminb commented 4 years ago

Hello @michael-flagg-vtas, thanks for the PR.

Please rebase your brach from current develop to resolve conflicts.

ghost commented 4 years ago

Thanks @jasminb - I've rebased my branch.

Veritas-MattG commented 4 years ago

Hello! If you have questions about this PR or requests to change it over the next week, please contact me.

BorisJineman commented 4 years ago

Hi Team,

Actually this PR is what we were looking for. Some related resources are not necessary.

For the reason of reducing data size, we might only set an links object but without data in relationship objects,

But in this PR, I think we might also need to consider to remove the resource objects from the the included resource objects.


In our side, we simply adjust this part codes a bit, and allow null value relationship fields to generate relationship objects if links or meta presenting. Thus we can control it during run-time.

Move `if (relationshipObject != null) {` at line 844 to where we were going to set the data.

Peace and Long Life, Boris

BorisJineman commented 4 years ago

I checked in the changes at #227 ;)

jasminb commented 4 years ago

Merged, ty @michael-flagg-vtas!

ghost commented 4 years ago

Thanks @jasminb - much appreciated!