Skip to content

Tag: jersey

Jersey 1 @Inject migrated to Jersey 2 stopped working

I am doing a Jersey 1 to Jersey 2 migration of my system. In my code I had @Inject annotation from com.sun.jersey.spi.inject.Inject and @Singleton from com.sun.jersey.spi.resource.Singleton. I’ve changed these to javax.inject.Inject and javax.inject.Singleton. Since this change I am getting errors while injecting any object annotated with it. My error is this The APIConnectorHandler is Injected both in RSearchClient and BarcodeSearchClient.

Get file resource in a Jersey 3

I am running a web application using Jersey. In my controller, I am trying to get a file in src/main/resources folder. My folder structure is: My gradle dependencies are: My code is: How do I get an InputStream for this file? Answer You can get it by servletContext.getResourceAsStream Add ServletContext using @Context If you are missing import jakarta.servlet.ServletContext add to

Get object from .readEntity

I have a java service which calls an API and gets the following in return How can i use .readEntity (or something else) to get the object for a given field; say service2 Or just convert all objects inside status to a List<> of objects String output = response.readEntity(String.class); works, but i dont know how to parse it properly to

JAX-RS (jersey implementation) ExceptionMapper aren’t catching ConstraintViolationException

I have an ExceptionMapper as a @Provider for handling all of my exceptions. So it is obvious that my class implements ExceptionMapper<Throwable> and we as know, all exceptions are extended Throwable somehow. Now I used jax-rs @NotNull to checking my resources input values to be not null and by some search, I realized it will throw ConstraintViolationException when the annotated

Jackson adds backslash in json

I’m building REST service on Jersey and using Jackson to produce JSON from java classes of my model. Model with absolutely simple values, I think this is the most typical case. But I get strange result: My expecting result: My source values of fields does NOT contains any special characters. These are simple words. There’re my Java classes. Entity: Class