That makes sense, but unfortunately, the code is already using it in
deserialization... in BeanJsonConverter, line 89-119ish, the getSetter
method calls getPropertyName which uses the annotation.

So, can this be safely changed to check for a different annotation name,
like JsonSetterProperty, while leaving the serialization code the same?
Because as it stands, its sorta broken. If no one is supposed to be using
it, then I suppose it shouldn't affect anyone.

- Cassie


On Wed, Jul 29, 2009 at 3:39 PM, Kevin Brown <[email protected]> wrote:

> JsonProperty was originally only added for serialization (as indicated by
> the documentation). It could certainly be used for deserialization, but the
> BeanJsonConverter and JsonSerializer both need to be updated accordingly.
>
> On Wed, Jul 29, 2009 at 3:28 PM, Cassie <[email protected]> wrote:
>
> > Hey everyone -
> >
> > I have some legacy objects in my code base that I wanted to convert to
> and
> > from json with the BeanJsonConverter and JsonProperty. Problem is, it
> seems
> > that the same logic/annotation is being used to find getters and setters
> on
> > my pojos. So when I try to convert my pojo to a string, it ends up trying
> > to
> > call setters, and not getters (or vice versa).
> >
> > For example, I have a class Post.java with two fields "title" and "body".
> > Add setters and getters for these fields and things work dandy. However,
> I
> > need my json to use capital case: "Title" and "Body". To do this I figure
> I
> > need JsonProperty. So I go and add the JsonProperty("Title") and the
> other
> > annotation to the setters and who hoo I can take my json into a pojo with
> > capital case. But then - on the way from pojo to json the code grabs all
> > methods, and if they have a jsonProperty - it puts them in the getter
> map!
> > Unfortunately, this causes an IllegalArgException because of course my
> > setters take params, and the code is expecting them to be getters...
> >
> > So, I'm thinking we either need a JsonGetProperty and JsonSetProperty
> > annotation. Or, the code needs to check that a property exists -and- that
> > the method starts with "get" or "set" or maybe there is something
> better...
> >
> > Anyway, did I completely screw something up here? Is someone getting this
> > to
> > work correctly?
> > If not, how should we fix it?
> > Thanks!
> >
> > - Cassie
> >
>

Reply via email to