Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. @Path("/test")
  2. public class TestResource {
  3.  
  4. @GET
  5. @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  6. @XmlElementWrapper( name= "tests")
  7. @XmlElements({
  8. @XmlElement(name= "coolTest", type=CoolTest.class)
  9. /**Add other type of test that are managed by this resource **/})
  10. public List<Test> getTests(){
  11. List<Test> tests = new ArrayList<Test>();
  12. tests.add(new CoolTest("1", "Cool"));
  13. return tests;
  14. }
  15. }
  16.  
  17. @XmlTransient
  18. public abstract class Test {
  19.  
  20. private String id;
  21.  
  22. public Test(){}
  23.  
  24. public Test(String id){
  25. this.id = id;
  26. }
  27.  
  28. @XmlElement
  29. public String getId() {
  30. return id;
  31. }
  32.  
  33. public void setId(String id) {
  34. this.id = id;
  35. }
  36. }
  37.  
  38. @XmlRootElement
  39. public class CoolTest extends Test{
  40.  
  41. private String coolMsg;
  42.  
  43. public CoolTest(){}
  44.  
  45. public CoolTest(String id, String coolTest){
  46. super(id);
  47. this.coolMsg = coolTest;
  48. }
  49.  
  50. @XmlElement
  51. public String getCoolMsg() {
  52. return coolMsg;
  53. }
  54.  
  55. public void setCoolMsg(String coolTest) {
  56. this.coolMsg = coolTest;
  57. }
  58. }
  59.  
  60. SEVERE: A message body writer for Java class java.util.ArrayList, and Java type java.util.List<org.arrowhead.wp5.core.model.Test>, and MIME media type application/xml was not found.
  61.  
  62. @XmlRootElement
  63. @XmlSeeAlso({CoolTest.class})
  64.  
  65. @Path("/test")
  66. @XmlRootElement
  67. public class TestResource {
  68.  
  69. @XmlElementWrapper(name = "tests")
  70. @XmlElements({@XmlElement(name="coolTestPotato", type=CoolTest.class)})
  71. public List<Test> getTestList(){
  72. List<Test> tests = new ArrayList<Test>();
  73. tests.add(new CoolTest("1", "Cool"));
  74. return tests;
  75. }
  76.  
  77. @GET
  78. @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  79. public TestResource getTests(){
  80. return this;
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement