Closed scotzark closed 2 years ago
Hello @scotzark,
Here is a unit test that demonstrates a working example for your use-case:
@Test
public void testSerializeWithoutId() throws DocumentSerializationException {
User user = new User();
user.setName("Name");
byte [] data = converter.writeDocument(new JSONAPIDocument<>(user));
System.out.println(new String(data));
}
And it produces:
{
"data": {
"type": "users",
"attributes": {
"name": "Name"
},
"relationships": {
"statuses": {}
}
}
}
If you are producing new resource to be stored, just make sure that the id
attribute is null
when converting and posting it to the server.
Hello again @scotzark,
I've addressed the issue in following commit 70e28cab11d9096e80c8ea958b2f4902bd62f32e which allows explicitly disabling id
serialization without having to resort to setting it to null
.
New release will be out in couple of days, in the meantime you can use SNAPSHOT
version.
Hi-
I have a server implementation that I am talking to that does not allow the 'id' field to be present in the created resource. It returns an error code. The developer of the server has pointed to this part of the JSON API spec:
"Exception: The id member is not required when the resource object originates at the client and represents a new resource to be created on the server."
I do not see a way to tell the ResourceConverter to exclude the ID field on serialization, only on deserialization. Have you run into this issue before?