Remove "type" from JSON output jersey moxy

RobAu picture RobAu · Jan 13, 2014 · Viewed 7.6k times · Source

How to remove the type from the JSON output that I have. I have a class/bean that contains output of a REST service.I'm using jersey-media-moxy to do the conversion.

The service

@Resource
public interface MyBeanResource
{
    @GET
    @Path("/example")
    @Produces( MediaType.APPLICATION_JSON )
    public Bean getBean();
}

The Bean

@XmlRootElement
class Bean
{
   String a;
}  

I want to add some functionality (for initializing the bean using the constructor)

class BeanImpl extends Bean
{
    BeanImpl(OtherClass c)
    {
        a = c.toString()
    }
}

The outputted JSON is:

{type:"beanImpl", a:"somevalue"}

I do not want the type in my JSON. How can I configure this?

Answer

Dennis Mitchell picture Dennis Mitchell · Feb 6, 2014

I get the same error when I extend a class and generate JSON -- but only for a top-level (root) class. As a workaround, I annotate my subclass with @XmlType(name=""), which prevents the generated type property from appearing in my JSON.

Blaise, I'm not sure why this works. Any thoughts?