Skip to content

Instantly share code, notes, and snippets.

@AdamBien
Created July 7, 2015 05:40
Show Gist options
  • Save AdamBien/a0fedea018c96f43f33a to your computer and use it in GitHub Desktop.
Save AdamBien/a0fedea018c96f43f33a to your computer and use it in GitHub Desktop.
17thAirhacksQ&A
Copy link

ghost commented Aug 11, 2015

Hello, Im new to JAX-RS approach and i've a particular questions. can anybody answer?

I've a method like following in a service class

@GET
@Produces(MediaType.APPLICATION_JSON)
    public Response listUsers( //PaginatedListWrapper
            @QueryParam("page") @DefaultValue("1") Integer page,
            @QueryParam("sortFields") @DefaultValue("id") String sortFields,
            @QueryParam("sortDirections") @DefaultValue("asc") String sortDirections) {

        PaginatedListWrapper listWrapper = new PaginatedListWrapper<>();
        listWrapper.setCurrentPage(page);
        listWrapper.setSortFields(sortFields);
        listWrapper.setSortDirections(sortDirections);
        listWrapper.setTotalResults(this.countAll());

        int start = (listWrapper.getCurrentPage() - 1) * listWrapper.getPageSize();
        listWrapper.setList(userFacade.findRange(new int[]{start, listWrapper.getPageSize()}));

        return Response.status(Response.Status.OK).entity(listWrapper).build();
    }

my PaginatedListWrapper class like follows

public class PaginatedListWrapper {
    private Integer currentPage;
    private Integer pageSize;
    private Integer totalResults;
 
    private String sortFields;
    private String sortDirections;
    private List list;

and im getting output like the following

Object {
currentPage: 1, 
list: Array[2],
0: "net.brac.ict.mis.tup.uplift.business.entities.User[ id=1 ]"
1: "net.brac.ict.mis.tup.uplift.business.entities.User[ id=2 ]" 
pageSize: 10, 
sortDirections: "asc", 
sortFields: "id"…
}

why im not getting the list of users as json object? like array of objects [{}, {}, {} ...]
what im missing here?
other than using jersey or jackson, i want to learn the underneath core stuffs of doing this.
in my maven it just javaee-web-api and eclipselink

Copy link

ghost commented Aug 12, 2015

Anyone please ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment