users@jersey.java.net

Re: [Jersey] RESTful API with optional XML elements/JSON properties

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Fri, 6 Mar 2009 20:04:24 -0800

On Fri, Mar 6, 2009 at 6:30 PM, Jaka Jančar <jaka_at_kubje.org> wrote:
> On 6. Mar 2009, at 20:52, Marc Hadley wrote:
>>
>> Consider using PATCH or POST instead. PUT is intended to replace the
>> representation at the request URI with the one you supply rather than
>> patching it as a diff. The latest spec for PATCH is here:
>>
>> http://www.ietf.org/internet-drafts/draft-dusseault-http-patch-13.txt
>
> PATCH is a good idea. POST would be wrong, I think, because it's meant to
> create a new resource under the one that's being POSTed to.
>
> But the problem remains even with PATCH:
>
> How to differentiate between no element and a null element on the Java-side
> of the mapping and how to get JAXB (or anything else) to map this correctly.

I don't know if this would be feasible, but one way this is often
handled in Java is to use a non-null marker instance of the object, to
denote "explicit null", and then regular null for missing.
Alternatively, setter-method could obviously track that a set was
made, but that requires more support.

-+ Tatu +-