jasminb / jsonapi-converter

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

When link has no meta it should render link as shortened version ("rel": "href") #182

Closed marceloverdijk closed 6 years ago

marceloverdijk commented 6 years ago

Currently links are rendered as:

{
  "links": {
    "self": {
      "href": "abc",
      "meta": {
        "foo": "bar"
      }
    }
  }
}

and without meta as:

{
  "links": {
    "self": {
      "href": "abc",
      "meta": null
    }
  }
}

or in case https://github.com/jasminb/jsonapi-converter/pull/181 is accepted as:

{
  "links": {
    "self": {
      "href": "abc"
    }
  }
}

Still not perfect. In case no meta is available I think rendering it to the below sample would be preferable:

{
  "links": {
    "self": "abc"
  }
}

This is also done like this in the jsonapi specs.

We could solve this by writing a custom JsonSerializer for the Link object.

Would you be interested in a PR for that?

jasminb commented 6 years ago

Quick thought, maybe this could be solved with meta-aware link getters in combination with disabling null value serialisation?

marceloverdijk commented 6 years ago

In general I do like null properties to be serialized, especially for the ”attributes” element of the resources.

But for the core jsonapi elements I don’t think it’s usefull, like the ”meta” element. And that’s also why I would prefer the shorthand version of the link if possible.

PS: I know I’m not consistent regarding serializing null values here 😇 (but at least it’s how I would prefer the output to look like)

marceloverdijk commented 6 years ago

I also don’t know how your quick thought would work because conditionally you wat the omit the href (shorthand variant) or not (in case meta is not null).

marceloverdijk commented 6 years ago

Closed as fixed by PR #188