JAX RS – 23 – JSON & MOXy

Merhaba Arkadaslar
Bu bolumde Jersey & MOXy JSON implementation’ini kullanacagiz.
RESTEasy ve Jersey Reference Documentetation’ini inceleyecek olursak daha farkli yaklasimda JSON provider’lari gorebiliriz. MOXy ile JSON provider konumuz son bulacak.

Maven Dependency

Jersey projemizde Jackson’i disable edelim , bunun yerine MOXy dependency tanimini ekleyelim.

pom.xml

<!-- 
<dependency>
	<groupId>org.glassfish.jersey.media</groupId>
	<artifactId>jersey-media-json-jackson</artifactId>
	<version>${jersey.version}</version>
</dependency>
	-->
	                 
<dependency>
	<groupId>org.glassfish.jersey.media</groupId>
	<artifactId>jersey-media-moxy</artifactId>
	<version>${jersey.version}</version>
</dependency>
 

Product.java

package _16.moxy.json.model;

public class Product {

	private int id;
	private String name;
	private String brand;
	private double price;
	private String category;
        //getters and setters
}

ProductResource.java

package _16.moxy.json.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import _16.moxy.json.model.Product;

@Path("/product-moxy-json")
public class ProductResource {

	@GET
	@Path("/product")
	@Produces(MediaType.APPLICATION_JSON)
	public Product getProduct() {
		Product product = new Product();
		product.setId(1);
		product.setName("K-360");
		product.setBrand("Logitech");
		product.setPrice(99.99);
		product.setCategory("Keyboard");
		return product;
	}
}

http://localhost:8080/injavawetrust.jersey.tutorial/product-moxy-json/product	

moxy-jersey

Github kaynak kodlar / source folder
injavawetrust.resteasy
injavawetrust.jersey

Yazimi burada sonlandiriyorum.
Herkese Bol Javali Gunler dilerim.
Be an oracle man , import java.*;
Levent Erguder
OCP, Java SE 6 Programmer
OCE, Java EE 6 Web Component Developer

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *