Beanable Interface Deprecation

Hi,

We are looking into replacing deprecated code, etc. The Beanable interface is one such item. Can anyone point me to a document or an explanation of what I need to do to replace it please?
Thanks,

Jim

The javadoc states: @Deprecated since 5.2. If you want a JSON-producing REST endpoint, then use a proper JAXRS resource.

This is documented here: https://developer.atlassian.com/server/framework/atlassian-sdk/rest-plugin-module/

Thank you very much.

1 Like

I have read this but I need more concrete information, like:
We import the Beanable Interface like so:
import com.atlassian.confluence.core.Beanable;
Do I need to import something else instead?

We implement Beanable like so:

public class PageStatusActionImpl extends ConfluenceActionSupport 
   implements PageAware, PageStatusAction, Beanable {

Do I need to implement something else instead? If so, what?

We override getBean like so:

@Override    
public Object getBean() 
{	return resultBean; }

Do I need to replace this? If so, with what?

We catch the result from getBean like so:

Map<String, Object> resultBean = new HashMap<String, Object>(); // for json result types
resultBean.clear(); 
resultBean.put(LABELRESULT, currentLabel);

Do I need to change this?

If Beanable is deprecated there must be somebody at Atlassian that has removed the code that uses Beanable from the Confluence code. Can they respond to this or be contacted?

This is the developer community forum. If you have support for Atlassian products, then input a support request.

I don’t know if i can explain how JAX-RS works in a comment. It’s not difficult, but it’s not simple either.

Thank you very much for your reply.

I have an example, but I am not sure how to apply it to your example. A serializable object is annotated like this –

import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonRootName;

@JsonRootName("post")
public class PostDTO {
    @JsonProperty
    private Long id;
    @JsonProperty
    private String title;
    @JsonProperty
    private String body;

    public PostDTO() {
    }

    public PostDTO(final Long id, final String title, final String body) {
        this.id = id;
        this.title = title;
        this.body = body;
    }

    public Long getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public String getBody() {
        return body;
    }
}

Then a class has methods annotated with methods and path options –

import com.atlassian.pocketknife.api.querydsl.DatabaseAccessor;
import com.atlassian.pocketknife.api.querydsl.util.OnRollback;

import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.OK;

@Named
@Path("/post")
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public class PostService {
    private final DatabaseAccessor databaseAccessor;
    private final PostDAO posts;

    @Inject
    public PostService(final DatabaseAccessor databaseAccessor, final PostDAO posts) {
        this.databaseAccessor = databaseAccessor;
        this.posts = posts;
    }

    @POST
    public Response create(PostDTO draft) {
        return Response.status(CREATED)
                .entity(databaseAccessor.runInNewTransaction(connection -> posts.create(draft, connection), OnRollback.NOOP))
                .build();
    }

    @GET
    public Response getAll() {
        return Response.status(OK)
                .entity(databaseAccessor.run(posts::getAll, OnRollback.NOOP))
                .build();
    }
}

Great stuff! Thank you. This gives me something to start with. :smiley:

Do you know of a package that has been upgraded from using Beanable? Then I can see what changed between the old and new versions.

I found a web page that recommends using /rest/quicknav/1/search instead but then I read one that said that “We ended support for this gadget in Confluence 7.0”. So the next question is: What do we use instead of QuickNav?