A follow up on the earlier question about updates. The problem is to
send an XML request over the wire that contains values for only and
all fields of a resource that are to be updated, even if the field is
to be updated to null.
The previous version of the REST implementation at my client (which I
am ugrading to use Jersey) solved this problem by using the attribute
xsi:nil=true in those elements that are to be updated to null in an
update request. So there are three cases:
1. An element corresponding to a field of a resource appears in the XML
for updating the resource. The field is to be updated.
1.a. The XML element has a value. Update the field to that
value.
1.b. The XML element has no value but has an xsi:nil=true
attribute.
Update the field to null.
2. An element corresponding to the field does not appear in the XML for
updating the resource. Do not update the field.
This is a clean solution to the issue of distinguishing the two
different interpretations of null in an update: one meaning update to
null, the other meaning this field is not participating in the update.
But I am not sure whether this solution can be implemented simply in
Jersey.
The problem is that the representation of null as an xsi:nil=true
element is dynamic. Some of the time, the field need not be updated,
and hence the corresponding element should not appear at all in the
XML. So I cannot simply use the @XmlElement(nillable = true) annotation
on the corresponding field definition in the Java bean for the
resource.
Also I don't know if it easy in the resource's PUT method to find out
if the null value was passed explicitly via the xsi:nil attribute or
implicitly via a missing element.
Are there simple ways to implement this solution in Jersey, preferably
without resorting to filters and direct examination of the payload XML?
Many thanks.
Azad