Skip to content

[Java] Migrate okhttp Gson readers to JsonReader.setStrictness #25853

Backlog

Description

@konard

Description

OpenAPI Generator CLI 7.28.0 emits two deprecated JsonReader.setLenient(true) calls in the Java okhttp-gson client. Its okhttp library emits the same calls when Gson is selected. I reproduced two javac deprecation diagnostics after upgrading the generated Maven project's gson-version from 2.10.1 to 2.15.0. Both templates on the current default branch also call the old setter.

Minimal reproduction

Create ping.yaml:

openapi: 3.0.3
info:
  title: Gson reader reproduction
  version: 1.0.0
paths:
  /ping:
    get:
      operationId: ping
      responses:
        '200':
          description: OK

Generate the okhttp-gson client and compile with current Gson and deprecation diagnostics enabled:

java -jar openapi-generator-cli-7.28.0.jar generate \
  -i ping.yaml -g java --library okhttp-gson -o out
rg -n 'jsonReader.setLenient\(true\)' out/src/main/java
cd out
mvn -Dgson-version=2.15.0 -Dmaven.compiler.showDeprecation=true -DskipTests compile

The generated JSON.java uses the legacy setter in deserialize(String, Type) and deserialize(InputStream, Type). Both paths are affected even with a spec containing only one operation.

Workaround and suggested upstream change

Router compiles the generated client against Gson 2.15.0 and substitutes this line in the two generated overloads:

jsonReader.setStrictness(com.google.gson.Strictness.LENIENT);

The Java probe exercises both overloads with a comment and a single-quoted string. Gson introduced Strictness in 2.11.0. Please update the Gson dependency floor in the Java templates that adopt it, then update both overloads to call setStrictness(Strictness.LENIENT). Gson documents this as the equivalent of setLenient(true).

Gson 2.15.0 setter and deprecation guidance

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions