IBM / java-sdk-core

Core functionality required by Java code generated by the IBM Cloud OpenAPI SDK Generator (openapi-sdkgen)
https://ibm.github.io/java-sdk-core/
Apache License 2.0
20 stars 21 forks source link

java.lang.NoClassDefFoundError: com/google/gson/internal/reflect/ReflectionAccessor #168

Closed NickKanellos closed 2 years ago

NickKanellos commented 2 years ago

Hey, ya'll. Do ya'll know about this?

Cross posting this issue here: https://github.com/IBM/cloudant-java-sdk/issues/253 & https://github.com/IBM/cloudant-java-sdk/pull/236

Describe the bug

java.lang.NoClassDefFoundError: com/google/gson/internal/reflect/ReflectionAccessor
 at com.ibm.cloud.sdk.core.util.DynamicModelTypeAdapterFactory.(DynamicModelTypeAdapterFactory.java:77)
 at com.ibm.cloud.sdk.core.util.GsonSingleton.registerTypeAdapters(GsonSingleton.java:77)
 at com.ibm.cloud.sdk.core.util.GsonSingleton.createGson(GsonSingleton.java:53)
 at com.ibm.cloud.sdk.core.util.GsonSingleton.getGsonWithoutPrettyPrinting(GsonSingleton.java:102)
 at com.ibm.cloud.sdk.core.http.RequestBuilder.bodyContent(RequestBuilder.java:417)
 at com.ibm.cloud.cloudant.v1.Cloudant.postDocument(Cloudant.java:825)

To Reproduce

call com.ibm.cloud.cloudant.v1.Cloudant.postDocument() using

<dependency>
     <groupId>com.ibm.cloud</groupId>
     <artifactId>cloudant</artifactId>
     <version>0.0.36</version>
</dependency>

and

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.9.0</version>
</dependency>

Unfortunately I can't use an earlier version of GSON because of this: https://github.com/google/gson/issues/1875 and this https://github.com/google/gson/pull/1902

Must gather (please complete the following information):

$ java --version
openjdk 16.0.2 2021-07-20
OpenJDK Runtime Environment Temurin-16.0.2+7 (build 16.0.2+7)
OpenJDK 64-Bit Server VM Temurin-16.0.2+7 (build 16.0.2+7, mixed mode, sharing)
padamstx commented 2 years ago

Yes, we're aware that SDKs cannot yet upgrade to gson 2.9.0. The latest version the java core can use is currently 2.8.9, and we have an issue on our backlog to migrate to gson 2.9.0: https://github.ibm.com/arf/planning-sdk-squad/issues/3106

padamstx commented 2 years ago

Version 9.15.5 of the java core has been released which bumps up the gson dependency to 2.9.0.

japhet99 commented 1 year ago

I try to use 22.3.0,is ok,successful , last , look my pom.xml and picture

pom.xml

<!--  stripe   begin -->
        <dependency>
            <groupId>com.sparkjava</groupId>
            <artifactId>spark-core</artifactId>
            <version>2.9.4</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.10.1</version>
        </dependency>
        <dependency>
            <groupId>com.stripe</groupId>
            <artifactId>stripe-java</artifactId>
            <version>22.3.0</version>
        </dependency>
        <!--  stripe  end -->

java code

@Test
    public void test1() throws StripeException {
        Map<String, Object> params = new HashMap<>();
        params.put("name", "product1 ----");
        List<String> list = new ArrayList<>();
        for (String pic : "a.jpg,b.jpg,c.jpg".split(",")) {
            list.add(pic);
        }
        params.put("images", list);
        params.put("description", "描述。。。");
        logger.info("----------");
        Product product = Product.create(params);
//        Product product = stripeService.createProduct(params);
        logger.info("-----"+product.toString());
    }

picture image image

padamstx commented 1 year ago

@japhet99 Your problem doesn't appear to be an issue with this particular repository. You must be using gson in a different context.