Kong/unirest-java

Unable to load gson mapper

0utplay opened this issue · 3 comments

Describe the bug
When using the latest release candidates of unirest and the gson mapper, the GsonEngine is not loaded because there is a mismatch between the names in unirest and the unirest gson mapper. The gson mapper calls the service "kong.unirest.core.json.JsonEngine", but in RC2 the json engine is still in "kong.unirest.json.JsonEngine". Due to this difference, the java ServiceLoader cannot load the GsonEngine and the entire json mapping with unirest does not work.

To Reproduce
Use unirest-java 4.0.0-RC2 with unirest-object-mappers-gson 4.0.0-RC7 and try to run the following code

import java.util.Collection;
import kong.unirest.GenericType;
import kong.unirest.Unirest;

public class TestCase {

  private static final GenericType<Collection<String>> DOCUMENT_COLLECTION_TYPE = new GenericType<>() {
  };

  public static void main(String[] args) {
    var response = Unirest.get("https://meta.fabricmc.net/v2/versions/installer")
      .accept("application/json")
      .asObject(DOCUMENT_COLLECTION_TYPE);
    if (response.isSuccess()) {
      System.out.println(response.getBody());
    } else {
      System.out.println(response.getParsingError().get());
    }
  }
}

Expected behavior
The GsonEngine is loaded and the mapping of the body works.

Screenshots
This is the service file in the mapper
image
This is the json engine class in unirest-java
image

Environmental Data:

  • Java 17
  • unirest-java 4.0.0-RC2
  • unirest-object-mappers-gson 4.0.0-RC7

Additional context
This is the parsing error that occurs.

kong.unirest.UnirestParsingException: kong.unirest.UnirestConfigException: No Json Parsing Implementation Provided
Please add a dependency for a Unirest JSON Engine. This can be one of:
<!-- Google Gson (the previous core impl) -->
<dependency>
  <groupId>com.konghq</groupId>
  <artifactId>unirest-object-mappers-gson</artifactId>
  <version>${latest-version}</version>
</dependency>

<!-- Jackson -->
<dependency>
  <groupId>com.konghq</groupId>
  <artifactId>unirest-object-mappers-jackson</artifactId>
  <version>${latest-version}</version>
</dependency>)

I've seen that the JsonEngine is now located in kong.unirest.core.json when browsing the latest state of the branch https://github.com/Kong/unirest-java/blob/jv11/unirest/src/main/java/kong/unirest/core/json/JsonEngine.java but as there is no RC3 i can't use that.

ryber commented

I thought I had published the fix a long time ago, but apparently that release, and another I did yesterday are not in maven central, which was weird because it uploaded just fine and I didn't get a rejection email. So I'm going to open a issue with them to see what the deal is.

ryber commented

well, before opening a ticket I decided to make sure all my maven stuff was up to date, and tried it again, and then it worked. So it should be good now with RC9 (hopefully the last RC)

Thanks! This resolved the issue for me.

I would suggest changing the URL provided in the release
image
As the package is unirest-java-core and unirest-java is not getting any of these updates. I've been confused with this rn until I noticed the other packages.