jersey

Unwrap a element in Jackson/Jaxb

痴心易碎 提交于 2019-12-18 06:50:44
问题 I am using Jersey+Jackon to make a REST API which works with JSON. Assume that I have a class as follows: @XmlRootElement public class A { public String s; } and here is my jersey method which uses the class: @GET @Produces(MediaType.APPLICATION_JSON) public Object get(@PathParam("id") String id) throws Exception{ A[] a= new A[2]; a[0] = new A(); a[0].s="abc"; a[1] = new A(); a[1].s="def"; return a; } the out put is: {"a":[{"s":"abc"},{"s":"def"}]} but I want it to be like this: [{"s":"abc"},

How to use jersey 2.0 guice on grizzly

你说的曾经没有我的故事 提交于 2019-12-18 05:59:14
问题 I want to use Guice + Jersey 2.0 on Grizzly. According to this How to use guice-servlet with Jersey 2.0? discussion there is no direct Guice integration for Jersey2 at present but it can be achieved using HK2 as a bridge. I also checked the sample project in Github https://github.com/piersy/jersey2-guice-example-with-test . This project is implemented using Jetty. But my problem is to implement it in Grizzly. On Jetty it is used like this @Inject public MyApplication(ServiceLocator

Return JSONArray instead of JSONObject, Jersey JAX-RS

﹥>﹥吖頭↗ 提交于 2019-12-18 05:55:57
问题 I am using Jersey to make some of my services RESTful. My REST service call returns me {"param1":"value1", "param2":"value2",...."paramN":"valueN"} But, I want it to return ["param1":"value1", "param2":"value2",...."paramN":"valueN"] What are the changes I need to make in the code below? @GET @Produces(MediaType.APPLICATION_JSON) public List<com.abc.def.rest.model.SimplePojo> getSomeList() { /* Do something */ return listOfPojos; } Part of my web.xml file looks like this <servlet> <servlet

How to use Jersey interceptors to get request body

痞子三分冷 提交于 2019-12-18 05:37:21
问题 I am using REST-Jersey in my project. All the POST data is send in JSON format and unmarshalled at server-side into respective beans. Something like this: Sending request to server: $('a#sayHelloPost').click(function(event){ event.preventDefault(); var mangaData = { title:'Bleach', author:'Kubo Tite' } var formData=JSON.stringify(mangaData); console.log(formData); $.ajax({ url:'rest/cred/sayposthello', type: 'POST', data: formData, dataType: 'json', contentType:'application/json' }) });

Registering a custom ResourceMethodInvocationHandler in Jersey

自作多情 提交于 2019-12-18 05:12:17
问题 I am attempting to intercept a resource call after it's JSON has been unmarshalled. Reading through some forums and posts I discovered that I may be able to do so by implementing org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider . Having done so I am now stuck trying to get my CustomResourceMethodInvocationHandler provider registered so that the jersey/hk2 internals call my overridden public InvocationHandler create(Invocable invocable) method. Any help would be

Spring+Jersey transactional annotation

拈花ヽ惹草 提交于 2019-12-18 04:47:11
问题 Created boilerplate project to expose RESTful API to JPA enabled database. It's using the following versions: - Spring 3.2.6 - Hibernate 4.3.0 - Jersey 2.5.1 I finally was able to get them playing together, but still some question remains. Here's one of the most puzzling things (see excerpt from REST service class) @Service @Path("resources") @Produces({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON }) @Transactional public class ResourceServices extends

A message body writer for Java class … and MIME media type text/html was not found [duplicate]

别等时光非礼了梦想. 提交于 2019-12-18 04:38:14
问题 This question already has answers here : How to produce JSON output with Jersey 1.6 using JAXB (6 answers) Closed 6 years ago . I am using the jms/atmosphere framework to make communication between two applications. One of the applications is a message producer for a topic, sending custom objects of the following type: @XmlRootElement public class A implements Serializable{ public A(){} /* some private properties */ } On the other side more than one consumers are listening on the topic and

Passing an object to a REST Web Service using Jersey

ε祈祈猫儿з 提交于 2019-12-18 04:20:43
问题 I have a simple WS that is a @PUT and takes in an object @Path("test") public class Test { @PUT @Path("{nid}"} @Consumes("application/xml") @Produces({"application/xml", "application/json"}) public WolResponse callWol(@PathParam("nid") WolRequest nid) { WolResponse response = new WolResponse(); response.setResult(result); response.setMessage(nid.getId()); return response; } and my client side code is... WebResource wr = client.resource(myurl); WolResponse resp = wr.accept("application/xml")

Use different paths for public and private resources Jersey + Spring boot

ぃ、小莉子 提交于 2019-12-18 04:02:35
问题 I'm using Spring boot + Jersey + Spring security, I want to have public and private endpoints, I want an schema as follow: /rest -- My root context /public -- I want to place my public endpoints in this context, It must be inside of the root context like /rest/public/pings /private -- I want to place my private endpoints in this context, It must be inside of the root context like /rest/private/accounts I have my configuration as follow: Jersey configuration: @Configuration @ApplicationPath("

Use different paths for public and private resources Jersey + Spring boot

夙愿已清 提交于 2019-12-18 04:02:29
问题 I'm using Spring boot + Jersey + Spring security, I want to have public and private endpoints, I want an schema as follow: /rest -- My root context /public -- I want to place my public endpoints in this context, It must be inside of the root context like /rest/public/pings /private -- I want to place my private endpoints in this context, It must be inside of the root context like /rest/private/accounts I have my configuration as follow: Jersey configuration: @Configuration @ApplicationPath("