3

I have a project where I use RESTful web service on the server side to get and post data. It works fine if I specify the MediaType as XML (in @Consumes and @Produces, but it doesn't when it comes to JSON. Here is an example of a method

@GET
@Path("{id}")
@Produces({MediaType.APPLICATION_JSON})
public Product find(@PathParam("id") Integer id) {
    return super.find(id);
}

When I try to call the service it throws the following exception:

javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper

However, I tried to do what's explained in the answer of this question how correctly produce json by restful web service, but it changed nothing.

Community
  • 1
  • 1
sqr_hussain
  • 63
  • 1
  • 1
  • 5

2 Answers2

2

It appears there is a bug in Eclipse Link. I think you may need to update to EclipseLink 2.6.1 and Jersey 2.19 or later see also this link. Otherwise you may be missing a dependency of org.eclipse.persistence.jaxb.BeanValidationHelper, since that class exists on your classpath but gets an exception trying to load into the JVM.

hack_on
  • 2,532
  • 4
  • 26
  • 30
  • When I try to add Jersey library, EntityManager.createCriteriaQuery becomes unknown. I found the reason is that this library contains persistence.xml but I have no idea what to do in order to make my project work along with Jersey. – sqr_hussain Dec 18 '15 at 01:09
  • I see that it is Jersey and Hibernate incompatibility problem. But before You put the new jar, you must have had a Jersey jar of some type? Cant you just update that? – hack_on Dec 18 '15 at 03:33
1

You need download this file

https://mega.nz/#!Ck0lVSRA!_KIjTl_8scQrak7jNTBepv3oqSKgeYsAVqjlvAarTbU

and replace in the next path:

C:\Program Files\glassfish-4.1.1\glassfish\modules

after open and close the IDE in my case I use Netbeans, test the RESTful.

Victor Jimenez
  • 598
  • 3
  • 6
  • 1
    Just tried the solution mentioned here http://stackoverflow.com/questions/33722764/glassfish-error-when-producing-json which describes the necessary steps to have the updated jar mentioned in @Victor Jimenez answer. Works like a charm. – Spielername Feb 17 '17 at 10:08