RESTEasy +Jackson 2 进行JSON转换
程序员文章站
2022-07-16 22:34:58
...
1. 整合RESTEasy和Jackson2
需要引入resteasy-jackson-provider.jar
2.一个简单的Object
3. REST Service
4. RUN
请求:http://localhost:8080/resteasy-example/hello/customer/json
需要引入resteasy-jackson-provider.jar
2.一个简单的Object
package com.example.rest.resteasy.model; public class Customer { private int id; private String firstName; private String lastName; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } }
3. REST Service
package com.example.rest.resteasy.service; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import com.example.rest.resteasy.model.Customer; @Path("/hello") public class HelloWorldRestService { @GET @Path("/customer/json") @Produces("application/json") public Customer getProductInJSON() { Customer customer = new Customer(); customer.setFirstName("first"); customer.setLastName("last"); customer.setId(100); return customer; } }
4. RUN
请求:http://localhost:8080/resteasy-example/hello/customer/json
上一篇: HornetQ与JBoss4集成
推荐阅读
-
excel2json软件使用方法(Excel表快速转换成JSON字符串)
-
bootstrap搜索建议插件suggest+使用FastJSON进行JSON和String转换解析
-
使用开源项目JAVAE2 进行视频格式转换
-
RESTEasy +Jackson 2 进行JSON转换
-
Jackson 框架,轻易转换JSON
-
fastjson和jackson JSON转换实践
-
Jackson 框架,轻易转换JSON
-
spring boot @ResponseBody转换JSON 时 Date 类型处理方法,Jackson和FastJson两种方式。
-
json转换工具之Jackson工具类
-
spring boot2 修改默认json解析器Jackson为fastjson