`
flycun2
  • 浏览: 26829 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

RESTEasy +Jackson 2 进行JSON转换

阅读更多
1. 整合RESTEasy和Jackson2
需要引入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


  • 大小: 6.2 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics