jersey-2.0

Jackson not consuming the JSON root element

无人久伴 提交于 2020-01-12 08:07:38
问题 I'm using JAX-RS + Jersey to consume the web-service request and Jackson to translate JSON data: @Path("/") public class JAXRSRestController { @Path("/jsonRequest") @POST @Consumes(MediaType.APPLICATION_JSON) public Response submitJsonRequest(SampleObject sampleObject, @Context HttpHeaders headers) { Ack ack = new Ack(); ack.setUniqueId(sampleObject.getId()); ack.setType(sampleObject.getName()); return Response.ok().entity(ack).build(); } } Here if the request is in the below format, it would

Jackson not consuming the JSON root element

折月煮酒 提交于 2020-01-12 08:05:30
问题 I'm using JAX-RS + Jersey to consume the web-service request and Jackson to translate JSON data: @Path("/") public class JAXRSRestController { @Path("/jsonRequest") @POST @Consumes(MediaType.APPLICATION_JSON) public Response submitJsonRequest(SampleObject sampleObject, @Context HttpHeaders headers) { Ack ack = new Ack(); ack.setUniqueId(sampleObject.getId()); ack.setType(sampleObject.getName()); return Response.ok().entity(ack).build(); } } Here if the request is in the below format, it would

DELETE Request with Payload or Form Data causes Bad Request

送分小仙女□ 提交于 2020-01-11 10:25:11
问题 I am building a RESTful Web Service with Java Jersey 2.17. The Client for it. I am developing with ExtJS 5. My classes on the service Main.java public class Main { public static final String BASE_URI = "http://localhost:8080/app/rest/"; public static HttpServer startServer() { final ResourceConfig rc = new ResourceConfig(); rc.packages(true, "app"); rc.register(ResponseCorsFilter.class); return GrizzlyHttpServerFactory.createHttpServer(URI.create(Main.BASE_URI), rc); } public static void main

How to inject Grizzly Request into Jersey ContainerRequestFilter

怎甘沉沦 提交于 2020-01-11 07:11:28
问题 I have Jersey being provided by Grizzly. I have a ContainerRequestFilter implementation class. However this class is created once for all incoming requests. Therefore doing this: public class EndpointRequestFilter implements ContainerRequestFilter { @Context private org.glassfish.grizzly.http.server.Request requestContext; public void filter( ContainerRequestContext req ) throws IOException { // remove for sake of example } } The requestContext is null. I can inject the context into the

Adding JAR with ObjectMapper makes my ObjectMapper non-discoverable

狂风中的少年 提交于 2020-01-11 05:33:27
问题 How can I make my object mapper work in situation when there is another object mapper defined in jar from dependencies ? I'm trying to use Swagger with Jersey 2 which is being run under Jetty. The problem is that as soon as I add Swagger JAX-RX jar into classpath my object mapper is not discovered therefore I lose custom serialization of my objects. Here is how my object mapper defined @Provider public class ObjectMapperProvider implements ContextResolver<ObjectMapper> { } I've posted issue

expected output is not displaying

让人想犯罪 __ 提交于 2020-01-07 09:26:32
问题 I am learing jersey,below is my program where the output should come like this 8-6-1990 but it is displaying 0-0-0.I dont know the actual reason,can anyone help me Multipleparam.java package com.rest; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; @Path("multi") public class Multipleparam { @GET @Path("{day}/{month}/{year}") public Response getUserHistory(@PathParam("{day}") int day, @PathParam("{month}") int month, @PathParam(

how to implement MessageBodyWriter method writeTo for json response?

不羁岁月 提交于 2020-01-07 06:44:26
问题 How should I configure writeTo method so that it convert detail to json response . @Override public void writeTo(Detail detail, Class<?> type, Type genericType, Annotation[] annotation, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { try { JAXBContext jaxbContext = JAXBContext.newInstance(detail.getClass()); // serialize the entity myBean to the entity output stream jaxbContext.createMarshaller().marshal

how to implement MessageBodyWriter method writeTo for json response?

做~自己de王妃 提交于 2020-01-07 06:44:01
问题 How should I configure writeTo method so that it convert detail to json response . @Override public void writeTo(Detail detail, Class<?> type, Type genericType, Annotation[] annotation, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { try { JAXBContext jaxbContext = JAXBContext.newInstance(detail.getClass()); // serialize the entity myBean to the entity output stream jaxbContext.createMarshaller().marshal

Designing REST resource to support multiple methods which produces and consumes exactly the same mime-types

人走茶凉 提交于 2020-01-07 05:35:25
问题 I have 3 methods in ProfileResource : @GET @Produces(MediaType.APPLICATION_JSON) public List<Profile> getAllProfiles() { return profileService.getAllProfiles(); } @GET @Path("{profileId}") @Produces(MediaType.APPLICATION_JSON) public Profile getProfile(@PathParam("profileId") String profileId) { return profileService.getProfile(profileId); } @GET @Produces(MediaType.APPLICATION_JSON) public Profile getProfileByName(@QueryParam("profileName") String profileName) { return profileService

org.apache.lucene.Version ClassNotFoundException during elasticsearch

匆匆过客 提交于 2020-01-06 12:25:51
问题 I am using elasticsearch-rest-high-level client 6.4.0 in my application, I have added all the dependant jars from lucene as listed in maven. This is the error I am getting [org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/apache/lucene/util/Version] with root cause java.lang.ClassNotFoundException: org.apache.lucene.util.Version I was using jersey1 before and my web.xml was like this <servlet> <servlet-name>Restful App</servlet-name> <servlet-class>com.sun