github infinum/kotlin-jsonapix v1.3.0-alpha01

pre-release2 hours ago

First alpha of 1.3.0. Pre-release — the new public API is worth exercising against a real server before a stable tag.

Highlights

Relationship<T> for to-one relationships

A @HasOne property declared Relationship<T> distinguishes four states, so a request can say "clear this relationship" rather than only "leave it alone":

State Written as Means
Unset member left out leave this relationship alone
Unlink "dog": {"data": null} remove the relationship
Linked(ResourceIdentifier("dog", "1")) "dog": {"data": {"type": "dog", "id": "1"}} point at a resource without sending it in included
Included(dog) "dog": {"data": {...}} plus included point at a resource and send it

JSON:API treats an absent member and {"data": null} as different instructions, and forbids a server from reading the first as the second. A single nullable property collapses both, so the library could only ever produce the absent form.

The nullable declaration keeps its behaviour and its byte-identical wire output. It is now legacy and will be dropped in the next major release.

copyModel

A model's JSON:API type and id live in private fields on JsonApiModel and are set after construction, so they are not constructor parameters. copy leaves them behind and the copy serializes as resource 0 — a wrong value rather than a failure.

copyModel is generated for every annotated model, takes the same named arguments as copy, and carries the type and id across. It also works on models that are not data classes, which have no copy at all.

api.update(OwnerModel(data = owner.copyModel(myFavoriteDog = Relationship.Unlink)))

A new lint check, JsonApiXCopyLosesIdentity, reports copy on an annotated model and offers to replace it.

Valid request documents

The Retrofit converter now drops the response-only top level members and the nulls that serialization emitted, which strict servers were rejecting with HTTP 400 on every write.

To-many relationship objects without a data member are accepted

com.infinum.jsonapix:lint is published for the first time

The module has been configured to publish since it was written, but deployAll never listed it, so no version of it has ever reached Maven Central. It ships from this release on.

What's Changed

  • Update version to 1.2.0 by @antunflas in #102
  • Update renovatebot/github-action action to v46 by @infinum-renovate-github-app[bot] in #104
  • Update all non-major dependencies by @infinum-renovate-github-app[bot] in #103
  • Update dependencies by @DrakslerT in #105
  • Update all non-major dependencies by @infinum-renovate-github-app[bot] in #106
  • Add Java 21 setup to CI workflow by @antunflas in #113
  • Update all non-major dependencies by @infinum-renovate-github-app[bot] in #114
  • Write a valid JSON:API request document by @antunflas in #116
  • Accept a to-many relationship object without a data member by @antunflas in #117
  • Let a to-one relationship say "clear this" by @antunflas in #123
  • Update version to 1.3.0-alpha01 by @antunflas in #124

Full Changelog: v1.2.0...v1.3.0-alpha01

Don't miss a new kotlin-jsonapix release

NewReleases is sending notifications on new releases.