Created
February 27, 2009 23:23
-
-
Save cowtowncoder/71769 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.util.*; | |
import javax.ws.rs.*; | |
import javax.ws.rs.core.MediaType; | |
/** | |
* Test root resource to show case use of JSON | |
*/ | |
@Path("/echo") | |
public class EchoNameAsJson | |
{ | |
@GET | |
@Path("name/{name}") | |
@Produces("text/plain") | |
public String nameAsString(@PathParam("name") String name, | |
@QueryParam("id") String id | |
) | |
{ | |
return "Name = '"+name+"'; id = '"+id+"'"; | |
} | |
@GET | |
@Path("json/{name}") | |
@Produces(MediaType.APPLICATION_JSON) | |
public NameBean nameAsBean(@PathParam("name") String name, | |
@QueryParam("id") String id | |
) | |
{ | |
return new NameBean(name, id); | |
} | |
/* | |
////////////////////////////////////////////////// | |
// Helper bean | |
////////////////////////////////////////////////// | |
*/ | |
final static class NameBean | |
{ | |
final String _name; | |
final String _id; | |
final int[] _data; | |
public NameBean() { } // for deserialization | |
public NameBean(String name, String id, int[] data) | |
{ | |
_name = name; | |
_id = id; | |
_data = data; | |
} | |
public String getName() { return _name; } | |
public String getId() { return _id; } | |
public int[] getData() { return _data; } | |
public void setName(String n) { _name = n; } | |
public void setId(String i) { _id = i; } | |
public void setData(int[] d) { _data = d; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment