user377628
user377628

Reputation:

Why is Jersey providing outdated data?

I have a List of objects in my provider class:

List<Workspace> workspaces = new ArrayList<Workspace>();

And I have a method which can provide this list of workspaces in JSON:

@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Workspace> workspaces() {
    return workspaces;
}

This does work. I have another method which updates the List like this:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<Workspace> create(Workspace workspace) {
    workspaces.add(workspace);
    return workspaces;
}

This also works: it returns the full list of workspaces, including the one just passed in.

The problem is that when I GET the resource again using the first method, any new items I POSTed using the second method are not there. The only items I see are one which were added by the provider class's constructor. How can I persist this data?

Upvotes: 0

Views: 35

Answers (1)

Sameer Naik
Sameer Naik

Reputation: 1412

May be then your POST call is operating on a different bean. Are these beans singleton? Try printing 'this' pointer in each call.

Upvotes: 1

Related Questions