You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Maurizio Cucchiara <mc...@apache.org> on 2011/12/20 17:23:47 UTC

Json Plugin & Enum type

Hi all,
while I was trying to jsonify an enum, I realized that the json writer uses
the value of the name property in order to serialize an enum (see
http://s.apache.org/Usi - row 286).
Although it looks like there was a general consensus on the use the name
properties (see http://s.apache.org/XRm), this looks wrong to me, since
name properties is final and there is no way to overwrite it.
The json writer should use instead toString method (which uses name by
default), such that the user can "customize" the value.
WDYT?


Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara

Re: Json Plugin & Enum type

Posted by Maurizio Cucchiara <mc...@apache.org>.
http://struts.apache.org/2.3.1/struts2-plugins/struts2-json-plugin/apidocs/org/apache/struts2/json/annotations/JSONFieldBridge.html

Re: Json Plugin & Enum type

Posted by Maurizio Cucchiara <mc...@apache.org>.
I understand what you mean, furthermore I found a workaround for it:

@JSONFieldBridge(impl = StringBridge.class)
public ENUM_TYPE getType() {
        return type;
}

Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara


On 20 December 2011 17:37, Dave Newton <da...@gmail.com> wrote:

> But some people use `toString()` as a generic "let's make this
> human-readable" method, so it could return essentially anything. I mean,
> it'd be escaped, so legal JSON, but I'm not sure that's what would be
> expected.
>
> I'm wary.
>
> d.
>
> On Tue, Dec 20, 2011 at 11:23 AM, Maurizio Cucchiara
> <mc...@apache.org>wrote:
>
> > Hi all,
> > while I was trying to jsonify an enum, I realized that the json writer
> uses
> > the value of the name property in order to serialize an enum (see
> > http://s.apache.org/Usi - row 286).
> > Although it looks like there was a general consensus on the use the name
> > properties (see http://s.apache.org/XRm), this looks wrong to me, since
> > name properties is final and there is no way to overwrite it.
> > The json writer should use instead toString method (which uses name by
> > default), such that the user can "customize" the value.
> > WDYT?
> >
> >
> > Twitter     :http://www.twitter.com/m_cucchiara
> > G+          :https://plus.google.com/107903711540963855921
> > Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
> >
> > Maurizio Cucchiara
> >
>

Re: Json Plugin & Enum type

Posted by Dave Newton <da...@gmail.com>.
But some people use `toString()` as a generic "let's make this
human-readable" method, so it could return essentially anything. I mean,
it'd be escaped, so legal JSON, but I'm not sure that's what would be
expected.

I'm wary.

d.

On Tue, Dec 20, 2011 at 11:23 AM, Maurizio Cucchiara
<mc...@apache.org>wrote:

> Hi all,
> while I was trying to jsonify an enum, I realized that the json writer uses
> the value of the name property in order to serialize an enum (see
> http://s.apache.org/Usi - row 286).
> Although it looks like there was a general consensus on the use the name
> properties (see http://s.apache.org/XRm), this looks wrong to me, since
> name properties is final and there is no way to overwrite it.
> The json writer should use instead toString method (which uses name by
> default), such that the user can "customize" the value.
> WDYT?
>
>
> Twitter     :http://www.twitter.com/m_cucchiara
> G+          :https://plus.google.com/107903711540963855921
> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
>
> Maurizio Cucchiara
>