jsonapi-converter
jsonapi-converter copied to clipboard
Ability to create resource identifier objects
Hi!
Json Api standard specifies the way to update relationships via a PATCH request(http://jsonapi.org/format/#crud-updating-relationships), for example: PATCH /articles/1/relationships/author
{
"data": { "type": "people", "id": "12" }
}
My entity, which is meant to be a resource identifier object looks like this:
@Type("role")
@JsonIgnoreProperties(ignoreUnknown = true)
public class RoleDto {
@Id
public final String id;
@JsonCreator
public RoleDto(
@JsonProperty("id") String id) {
this.id = id;
}
}
This is being serialized into:
{
"data": {
"type": "role",
"id": "partner-standard-user-role-id",
"attributes": {
}
}
}
Would it be possible to not include empty attributes
field?
Maybe with annotation ResourceIdentifierObject
- when present it would only include id
, type
and meta
if present.
Or serialization option NO_EMPTY_ATTRIBUTES
?
Cheers!
Something like this
if (attributesNode.size() == 0 && SerializationFeature.NO_EMPTY_ATTRIBUTES) {
dataNode.remove(ATTRIBUTES);
}
would work.
Should i submit a PR for it?
deleted my comment... I overlooked you first sentence.
Hello @thinh76,
Let me take a look and get back to you.
Hello @thinh76,
Feel free to submit a PR with a change to support your requirement.
Please make sure that you are using tabs
for indentation and that you add unit tests to cover the added changes, also make sure that all tests pass (mvn clean install).