users@jersey.java.net

Re: [Jersey] Rid off the _at_at symbol on JSON responses?

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Thu, 10 Dec 2009 15:32:04 -0800

2009/12/10 Felipe Gaścho <fgaucho_at_gmail.com>:
> thanks Brown,
>
> but if I need to add a new framework just to remove the @ then I
> prefer to convert the attributes in elements.. then it is
> solved........... no extra code needed.............

No new framework. And library (jar) in question is already bundled by
Jersey (although not 100% sure if jackson-jax-rs jar is).
Jackson is used for parsing and writing JSON by Jersey. Just need a
line or two of code to register provider (for
MessageBodyReader/Writer):



>  I know there are tons of JSON & XML parsers out there.. but I am
> trying to reduce the amount of code to deploy and configure..........
> so I am still looking for the Jersey roots :)

Right, and that's the point: Jackson comes with JAX-RS content
provider, out of the box.
No need to do anything super special. :-)
I like Jersey (and JAX-RS) in general -- like others have said,
default of using badgerfish/mapping notation is a historical artifact.
There are other ways too, like Jakub mentioned natural notation. Just
because something is the default should not mean users don't use it.
:-)
(that is, don't fear changing defaults)

-+ Tatu +-

ps. For completeness sake, here's the entry from Jackson FAQ:

---
In addition to adding jackson-jaxrs jar (and jackson core and mapper
jars it depends on, if not bundled by the JAX-RS implementation), you
will also need to register provider. There are 2 ways to do this:
    * Add root provider with JAX-RS registration mechanism; for
example, by returning provider class/instance from Rest Application
class.
    * Add 'META-INF/services/javax.ws.rs.ext.MessageBodyReader' file
with one entry, provider class name
(org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvide) (and similarly for
MessageBodyWriter) to a jar that gets loaded by JAX-RS implementation
(this can be done by post-processing jackson-jaxrs jar, for example).
Here's one implementation of second approach:
import java.util.*;
public final class RestApplication extends javax.ws.rs.core.Application
{
    public Set<Object> getSingletons() {
        HashSet<Object> singletons = new HashSet<Object>();
        singletons.add(new
org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider());
        return singletons;
    }
}
---