How to expose ActiveObject entities through REST module

M_S_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2014

In my (JIRA) plugin, I have ActiveObjects configured with a domain model, which I now want to expose through a REST interface. I have added a REST module and injected the ActiveObjects into it, so access to the domain model entites does work.

However, how do I expose the entities through the REST service? For example with a Todo entity, I tried to simply do

return Response.ok(todoEntity).build()

but it fails, basically with

A message body writer for Java class com.sun.proxy.$Proxy2813, and Java type class com.sun.proxy.$Proxy2813, and MIME media type application/xml was not found

I have also tried to annotate the Todo entity definition (which has to be an interface) with @XmlRootElement, etc. but it does not seem to help.

Is it truely required to copy data from AO entity objects into REST objects back and forth? (I understand that it may be desireable to separate these, but in effect they will be the same for my project).

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
M_S_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 30, 2014

I did not find another solution to this and ended up with writing objects and code to move back an forth between REST objects and AO entities. Not elegant, but it works.

radosun July 8, 2019

can you provide that code I am trying to do the same thing.

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2014
M_S_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2014

That post does not seem to be of much help. The recommendation is to annotate the model class with annotations to define the serialization/mapping. However, since an ActiveObjects entity is defined through an interface, while the actual object to be serialized is a (dynamically created) proxy, that approach does not help.

As I said, I already tried to annotate the Todo entity interface, but it did not have any effect on the problem.

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2014

Yes, you,re right I've missed the fact that with AO you've got proxies. It seems that what you're trying to do is quite hard and maybe impossible. Here's some discussions on that

https://answers.atlassian.com/questions/19413/combining-active-object-entities-with-jaxb-annotations-any-implementation-examples

https://answers.atlassian.com/questions/119357/rest-activeobjects-jsonmappingexception

So I would advice you to create a separate model (as you already know) for the REST repsponse.

TAGS
AUG Leaders

Atlassian Community Events