@Path("/logs")
public class LogsServiceImpl {
@Produces(MediaType.APPLICATION_JSON)
@GET
public SearchResultDto<ActionLogDto> getActionLogsSearchResult(@QueryParam("filter") LogsFilter filter, @QueryParam("sortColumns") ArrayList<SortColumnDto> sortColumns, @QueryParam("pageSize") int pageSize, @QueryParam("pageNumber") int pageNumber) {
...
To handle converting the two parameters filter and sortColumns from JSON, We have a simple ParamConverterProvider on the server-side that simply uses ObjectMapper to convert the objects (code below).
On the client-side, we're trying to map this call using RestyGWT.
public interface LogsService extends RestService {
@GET
@Path("/logs")
void getActionLogsSearchResult(@QueryParam("filter") ActionLogsFilter filter, @QueryParam("sortColumns") ArrayList<SortColumnDto> sortColumns, @QueryParam("pageSize") int pageSize, @QueryParam("pageNumber") int pageNumber, MethodCallback<SearchResultDto<ActionLogDto>> callback);
The problem is that without more instructions, RestyGWT seems to simply uses toString() to serialize the two parameters. We'd like to tell the framework to convert the two parameters to JSON to call the service. Is there a way to do this?
Thanks in advance,
Pascal
----
Reference:
ParamConverter we use on the server-side.
@Provider
public class RestProvider implements ParamConverterProvider {
@Context
private Providers providers;
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
// Check whether we can convert the type with Jackson.
final MessageBodyReader<T> mbr = providers.getMessageBodyReader(rawType, genericType, annotations,
MediaType.APPLICATION_JSON_TYPE);
if (mbr == null || !mbr.isReadable(rawType, genericType, annotations, MediaType.APPLICATION_JSON_TYPE)) {
return null;
}
// Obtain custom ObjectMapper for special handling.
final ContextResolver<ObjectMapper> contextResolver = providers
.getContextResolver(ObjectMapper.class, MediaType.APPLICATION_JSON_TYPE);
final ObjectMapper mapper = contextResolver != null ?
contextResolver.getContext(rawType) : new ObjectMapper();
// Create ParamConverter.
return new ParamConverter<T>() {
@Override
public T fromString(final String value) {
try {
return mapper.reader(rawType).readValue(value);
} catch (IOException e) {
throw new ProcessingException(e);
}
}
@Override
public String toString(final T value) {
try {
return mapper.writer().writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new ProcessingException(e);
}
}
};
}
}