CXF (2.7.10)-RESTful Services, JSON support

Source: Internet
Author: User

In CXF (2.7.10)-restful services describes the RESTful WebService service, where data transfer is based on XML format. If you want to transfer data based on JSON format, @Produces ("Application/xml") is modified to @Produces ("Application/json").

 Packagecom.huey.demo.ws;Importjava.util.List;ImportJavax.jws.WebService;ImportJavax.ws.rs.DELETE;ImportJavax.ws.rs.GET;ImportJavax.ws.rs.POST;ImportJavax.ws.rs.PUT;ImportJavax.ws.rs.Path;ImportJavax.ws.rs.PathParam;Importjavax.ws.rs.Produces;ImportJavax.ws.rs.core.MediaType;ImportCom.huey.demo.bean.Book;Importcom.huey.demo.bean.ResultMsg; @WebService Public InterfaceBookservice {@GET//Specify the request method@Path ("/BOOK/{ISBN}")//Specifies the URI of the resource@Produces ({Mediatype.application_json})//Specify the media type for request/response     PublicBook GetBook (@PathParam ("ISBN") String ISBN); @GET @Path ("/books") @Produces ({Mediatype.application_json}) PublicList<book>Getbooks (); @POST @Path ("/book") @Produces ({Mediatype.application_json}) Publicresultmsg addbook (book book); @PUT @Path ("/BOOK/{ISBN}") @Produces ({Mediatype.application_json}) PublicResultmsg Updatebook (@PathParam ("ISBN") String ISBN, Book book); @DELETE @Path ("/BOOK/{ISBN}") @Produces ({Mediatype.application_json}) PublicResultmsg Deletebook (@PathParam ("ISBN") String ISBN);}

Test.

A

b

C

D

E

CXF (2.7.10)-RESTful Services, JSON support

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.