java - When using Jersey JAX-RS, is there a way to differentiate between fields sent as null and fields not sent at all? -
i'm using jersey jax-rs jackson (for serialization/deserialization) implement set of rest services. when caller performs update operation (ex. put), i've followed convention null fields sent in request ignored when target updated. fields set actual value updated.
however, i'd prefer if differentiate between fields sent null vs fields weren't sent @ know clear fields explicitly sent null.
i can invent way accomplish this, i'm wondering if there's available in framework. seems common requirement.
if using json pojo support (init parameter com.sun.jersey.api.json.pojomappingfeature true in web.config) simple solution have "a smart setter" on pojo:
class mybean { private string foo; private string bar; private boolean fooset; public string getfoo() { return this.foo; } public void setfoo(string foo) { this.foo = foo; this.fooset = true; } public string getbar() { return this.bar; } public void setbar(string bar) { this.bar = bar; } public boolean isfooset() { return this.fooset; } } the jackson call setter if field present (no matter value) , ignore if field missing altogether.
for jaxb based json support don't know if setter ever called might necessary write custom messagebodyreader/messagebodywriters or specialized form of jsonjaxbcontext.
Comments
Post a Comment