Why is there no writer for an application like multimedia / json

Basically, I have a soothing service (message) that consumes ( application/json ) and produces ( application/json ). A single parameter for this service is an annotated java object.

I am using org.jboss.resteasy.client.ClientRequest to send a request to a service. However, I get this exception at the end of the client and the exception:

could not find entry for type content-type application/json .

Does this mean that I am missing some cans of the library or do I need to write my own script for the / json application?

I am using resteasy 1.1

Mark

+4
java json resteasy
source share
3 answers

Raman is right. Jettison is a valid option. You can also use Jackson. If you use maven, it is as simple as including the following pom dependencies in you:

  <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jackson-provider</artifactId> <version>2.3.2.Final</version> </dependency> 

At this point, you should have no problem writing code, for example:

  SomeBean query = new SomeBean("args") request.body("application/json", query); ClientResponse response = request.post(); 
+6
source share

Actually, I had the same problem, I solved it by adding a Jettison provider for type application / json mime. I don't know if jettison provider supports resteasy 1.1, but version 1.2 does. Also, if you are using jdk 1.6, you must exclude the javax.xml.stream:stax-api jar file, otherwise you will have a problem.

Here is an example:

 import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name="account") public class Account { private Long id; private String accountNo; public Account(){} public Account(String no) { accountNo=no; } @Id @XmlElement public Long getId() { return id; } public void setId(Long id) { this.id = id; } @XmlElement public String getAccountNo() { return accountNo; } public void setAccountNo(String a) { accountNo = a; } } 

and JAXB class:

 import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @Path("/account") public class AccountService { @GET @Path("/{accountNo}") @Produces("application/json") public Account getAccount(@PathParam("accountNo") String accountNo) { return new Account(accountNo); } } 

That's all, we have a good day!

+2
source share

Add a resource class or an exception method below

 @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) 
+1
source share

All Articles