I am using the Java Jersey framework(with Maven), and use IntelliJ as my IDE. I have encountered this runtime exception that ONLY happens when I try to run the code from the command line (using maven to compile and then java -jar ) but NOT when running within IntelliJ, which is strange.
I have some Java code that will try to make an HTTP GET on some remote URL and try to read the returned JSON into some Lombok POJO :
String targetUrl = "some valid URL";
WebTarget webTarget = client.target(targetUrl);
Response response = webTarget.request(MediaType.APPLICATION_JSON_TYPE).get();
ParseResponse parseResponse = response.readEntity(ParseResponse.class);
I am not sure why, but when it hits that last line that does the "readEntity()" method, I will get the error below:
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/json; charset=utf-8
This is strange, because I definitely have the jersey-media-json-jackson dependency specified in my pom.xml :
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.23</version>
</dependency>
and this is my POJO class that I was trying to readEntity() into :
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ParseResponse {
@JsonProperty("id")
private Integer id;
...Other params...
}
And like I mentioned before, it is strange that this only happens when I try to run on the command line like this but there is no error when running in IntelliJ:
mvn clean package
java -jar target/NameOfJar.jar
Did I miss something obvious here? I have looked at other people with similar issues like this online but haven't found a solution.
Thanks IS