users@jersey.java.net

[Jersey] Re: Consume Json Jersey Response

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Fri, 18 Mar 2011 10:29:38 -0700

On Fri, Mar 18, 2011 at 3:41 AM, Jakub Podlesak
<jakub.podlesak_at_oracle.com> wrote:
> I dunno, it is rather a question for Tatu.
> You may want to try using the @JsonProperty annotation
> on your field.
>
> Does it help?
>
> ~Jakub
>
> On 03/18/2011 11:27 AM, Colin Vipurs wrote:
>>
>> Thanks! Worked a treat.  Only problem I have now is that my objects
>> don't expose setters, only getters.  Can I configure jackson to use
>> fields rather than getters and setters?

Yes. By default, only public fields are used. However, you can do one
of two things:

(a) Add @JsonProperty annotation (either directly or via mix-ins)
(b) You can change minimum visibility for auto-detection;
@JsonAutoDetect annotation works on per-class basis (and as usual, via
mix-ins too). And for ultimate power you can implement
VisibilityChecker, register with mapper, if you really want fully
custom logic for exposing fields, getters, setters.

Using (b) is pretty simple; you can just define that all fields are
exposed (unless explicitly removed via @JsonIgnore), with something
like:

@JsonAutoDetect(fieldVisibility=Visibility.ANY) // default is
PUBLIC_ONLY, there are other choices too

Hope this helps,

-+ Tatu +-