Unable to get json output

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unable to get json output

beotse
I am writing a RESTful Web Service, I am able to get the expected result if I selected xml method.

When I selected json, the browser displayed

status: 500 (Internal Server Error)
message:Internal Server Error
description:The server encountered an internal error that prevented it from fulfilling this request.
exception:javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper

May I know how to fix it? Thank you.

System Environment
Windows 7 SP1 64bits
NetBeans IDE 8.2 (Build 201609300101)
java version 1.8.0_131
GlassFish Server Open Source Edition 4.1

Source Code
Users.java

Code:

package q;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class User {  
   private int id;
   private String name;
   private String profession;  
   
   public User(){}
   
   public User(int id, String name, String profession){
      this.id = id;
      this.name = name;
      this.profession = profession;
   }  
   public int getId() {
      return id;
   }  
   public void setId(int id) {
      this.id = id;
   }
   public String getName() {
      return name;
   }
   public void setName(String name) {
      this.name = name;
   }
   public String getProfession() {
      return profession;
   }
   public void setProfession(String profession) {
      this.profession = profession;
   }  
}




Bll.java

Code:

package q;

import java.util.ArrayList;  
import java.util.List;  

public class Bll
{
    public List<User> getAllUsers()
    {
        List<User> userList = null;

        User user = new User(1, "Maheh", "Teacher");
        userList = new ArrayList<User>();
        userList.add(user);
       
        User user2 = new User(2, "Hdhjb", "Programmer");
        userList.add(user2);
       
        return userList;
    }    
}




 Q.java

Code:

package q;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Path("q")
public class Q {

    @Context
    private UriInfo context;
    public Bll bll;

    public Q() {
        bll = new Bll();
    }
   
    @GET
    @Path("/Users")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List<User> getUsers()
    {
        return bll.getAllUsers();
    }
}







Loading...