Hi All,
I'm trying to do a fairly simple REST/ActiveObject example in my plugin. I have a very simple active object, and am trying to return it from a restful method. So far, I have tried the following (NOTE: ReportCategory.java (interface) has only 3 simple string fields...name, key and description...none unique):
First Attempt:
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("/list/{parent-key}")
public Response list(
@PathParam("parent-key") String parentKey
){
//the method service.listSubCategories(parentKey) returns an array
//of active objects ReportCategory[]
return Response.ok(service.listSubCategories(parentKey)).build();
}
Second Attempt:
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("/list/{parent-key}")
public ReportCategory[] list(
@PathParam("parent-key") String parentKey
){
return service.listSubCategories(parentKey);
}
Third Attempt:
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("/list/{parent-key}")
public Response list(
@PathParam("parent-key") String parentKey
){
GenericEntity<ReportCategory[]> responseEntity = new GenericEntity<ReportCategory[]>(service.listSubCategories(parentKey)){};
return Response.ok(responseEntity).build();
}
I've debugged through these methods, and the active objects are being loaded just fine. But I'm constantly getting the following error...I'm guessing because Jackson doesn't know anything about the ActiveObject proxy objects. I don't want to go to all the effort of creating value objects for every active object just for JSON, seems like a DRY violation - has anyone successfully returned an AO proxy from a RESTful method?
org.codehaus.jackson.map.JsonMappingException: No serializer found for class $Proxy1523 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) at org.codehaus.jackson.map.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:52) at org.codehaus.jackson.map.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:25) at org.codehaus.jackson.map.ser.std.ObjectArraySerializer.serializeContents(ObjectArraySerializer.java:123) at org.codehaus.jackson.map.ser.std.ObjectArraySerializer.serializeContents(ObjectArraySerializer.java:29) at org.codehaus.jackson.map.ser.std.StdArraySerializers$ArraySerializerBase.serialize(StdArraySerializers.java:56) at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:659) at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:271) at org.codehaus.jackson.map.ObjectWriter.writeValue(ObjectWriter.java:325) at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:556) at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
Cheers
Adam
Community moderators have prevented the ability to post new answers.
Hi Adam,
I also don't like the fact to create both an Entity and a Bean for each of your objects but I'm pretty sure, there is no way to avoid this in Jira.
AO expects an Interface which extends net.java.ao.Entity. Jackson expects a class or at least a mapping of your interface to an implementation: http://fasterxml.github.com/jackson-databind/javadoc/2.0.5/com/fasterxml/jackson/databind/module/SimpleAbstractTypeResolver.html
However there is an optional Jackson feature (which isn't available in Jira) called "MrBean". It creates "implementation classes (not just instances!) for interfaces and abstract classes": http://wiki.fasterxml.com/JacksonFeatureMaterializedBeans
It sounds nice but I'm not sure if it would work with an AO Entity properly.
Conrad
Hi Conrad!
Do you know if there is some updates around this issue? I'm wondering if MrBean is provided on newer Jira versions, but haven't found any documentation...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
MrBean is part of the Atlassian Maven Repository starting version 1.9.5 (https://maven.atlassian.com/content/repositories/external/org/codehaus/jackson/jackson-mrbean/1.9.5/) but till JIRA 6.4.12, jackson-mapper-asl version 1.9.1 is part of the distribution. Use http://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mrbean/1.9.1 instead.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm trying to do the same thing (using AO inside a REST services), and it looks like MrBean is only for deserialization.
https://github.com/FasterXML/jackson-modules-base/tree/master/mrbean
Enabled it in my code for *sending* objects coming from AO didn't fix the "No serializer found for class com.sun.proxy.$ProxyXXXX" error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.