FYI, DWR takes the name value approach:
 
http://getahead.org/dwr/server/dwrxml/converters/enum
> Date: Sat, 10 Nov 2007 00:51:55 -0500> From: [EMAIL PROTECTED]> To: 
> dev@struts.apache.org> Subject: Re: serialize enum to JSON (jsonplugin issue 
> 9)> > +1 for the JSON-RPC approach.> > On Nov 9, 2007 9:54 PM, Jeromy Evans 
> <[EMAIL PROTECTED]> wrote:> > What is "the correct" way to serialize an enum 
> to JSON?> >> > The struts2plugin can't handle enums quite right (Issue 9:> > 
> http://code.google.com/p/jsonplugin/issues/detail?id=9) and while trying> > 
> to finalize a patch I haven't found a consistent opinion.> >> > There's two 
> schools of thought:> > - an enum should be serialized as a value. eg. { 
> "prop":"name()" } or> > { "prop":ordinal() }> > - an enum should be 
> serialized an an object. eg. { "prop": {> > "name":"name()" } }> > The 
> advantage of the latter case is that additional properties of the> > 
> enumeration can be included.> >> > My quick survey of implementations are:> > 
> xstream with JsonHierarchicalStream and default converter : { "prop":> > 
> {"name"}}> > xstream with jettisonMapper driver and default converter : {> > 
> "prop":"name" }> > json-rpc-java: { "prop":{ "_name":"name", properties... 
> }}> > json.net: {"prop":ordinal}> >> > I think json-rpc-java is strictly 
> correct by serializing the enum as> > bean with a special _name property, 
> however I think the Jettison driver> > by value approach is closer to what a 
> javascript developer would> > naturally expect. The JsonHierarchicalStream 
> driver is unnatural> > because it supports deserialization. Json.net doesn't 
> have to contend> > with additional properties in enums and the ordinal value 
> is explicit.> >> > Has anyone seen a convention used a lot that's worth 
> borrowing? Or is> > this worthy of a yet another option for the result?> >> > 
> regards,> > Jeromy Eans> > 
> ---------------------------------------------------------------------> To 
> unsubscribe, e-mail: [EMAIL PROTECTED]> For additional commands, e-mail: 
> [EMAIL PROTECTED]> 
_________________________________________________________________
Are you ready for Windows Live Messenger Beta 8.5 ? Get the latest for free 
today!
http://entertainment.sympatico.msn.ca/WindowsLiveMessenger

Reply via email to