Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper

I have been trying to get a dto object in json format as a response from my webservice. Webservice is developed in Spring Framework. But, whenever I try to access my application either from curl or from browser it gives me following exception on server-side.

java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper

My dto is something like this:

public class UserDto {
  @JsonProperty 
    private String id;
  @JsonProperty
    private String userRole;
//.... Getter & Setters skipped
}

My controller method is like:

    @GET
    @Path("getUser")
    @Produces({"application/xml",MediaType.APPLICATION_JSON_VALUE})
    public  UserDto GetLoggedinUser() {
        return new UserDto("wasif kirmani");
    }

I don't know where am I going wrong?

Environment: Server: GlassFish 4.1.1 Java: 6EE

like image 988
Wasif Kirmani Avatar asked Jul 30 '26 03:07

Wasif Kirmani


1 Answers

There is probably a missing dependency in your project. Try to adding this dependency to your pom.xml

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.moxy</artifactId>
        <version>2.6.0</version>
    </dependency>

This is the EclipseLink project for Object-XML binding and JAXB implementation. This also includes JSON binding support.

Reference: http://wiki.eclipse.org/EclipseLink/Maven

like image 156
brunocrt Avatar answered Aug 01 '26 18:08

brunocrt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!