Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java][jersey2] remove warning using JsonMapper.builder #10734

Merged
merged 2 commits into from
Oct 30, 2021

Conversation

wing328
Copy link
Member

@wing328 wing328 commented Oct 30, 2021

  • remove warning using JsonMapper.builder
[WARNING] /Users/williamcheng/Code/openapi-generator/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/JSON.java:[24,10] [deprecation] configure(MapperFeature,boolean) in ObjectMapper has been deprecated

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @nmuesch (2021/01)

@wing328 wing328 added Client: Java Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc. labels Oct 30, 2021
@wing328 wing328 added this to the 5.3.1 milestone Oct 30, 2021
@wing328 wing328 marked this pull request as ready for review October 30, 2021 08:54
@wing328 wing328 merged commit 8551b0a into master Oct 30, 2021
@wing328 wing328 deleted the fix-warning-jsonmapper branch October 30, 2021 08:55
AndersSpringborg added a commit to Forsteholdet/openapi-generator that referenced this pull request Oct 31, 2021
* OpenAPITools-master: (457 commits)
  [java][jersey2] remove warning using JsonMapper.builder (OpenAPITools#10734)
  update scribejava to 8.x (OpenAPITools#10733)
  [powershell] add file upload support (OpenAPITools#10735)
  Add openapi-generator kotlin article (OpenAPITools#10731)
  [ts-angular]: add ts-ignore directives to avoid compilation errors (OpenAPITools#10713)
  rebalance circleci tests (OpenAPITools#10727)
  [java][okhttp-gson] update dependencies in pom.xml (OpenAPITools#10709)
  [java][jersey2] update plugins in pom.xml (OpenAPITools#10710)
  Fix library generation compatibility with Gradle 7.2 (OpenAPITools#10716)
  [kotlin-spring] change the suffix from ".kt" to "Controller.kt" when generating a controller class (OpenAPITools#10671)
  [cpprestsdk] CMake build system improvements (OpenAPITools#10660)
  adds get/setHasMultipleTypes to Java schema classes (OpenAPITools#10715)
  update microprofile to newer version (OpenAPITools#10714)
  Typescript saga immutablejs enhancements and small fixes (OpenAPITools#10444)
  add an option for configKey (OpenAPITools#10707)
  Allow specification of configkey for microprofile clients (OpenAPITools#10693)
  Update crystal client gitignore.mustache with shards related files (OpenAPITools#10698)
  Adds ComposedSchema to store schema composed schemas (OpenAPITools#10653)
  Adds setPrettyPrint and the reslver MethodValueResolver.INSTANCE (OpenAPITools#10683)
  [dart] Fix pub server URL (OpenAPITools#10695)
  ...
@snago
Copy link
Contributor

snago commented Mar 15, 2022

I noticed this line in a generated client:
JsonMapper.builder().configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);
and the history led me to this PR.

That line creates a builder, sets a config and then throws the builder away. Totally non-sensical.

To use a builder it should look something like this:

    mapper = JsonMapper.builder()
                       .serializationInclusion(JsonInclude.Include.NON_NULL)
                       .configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false)
                       .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
                       .configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, true)
                       .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
                       .enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)
                       .enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
                       .defaultDateFormat(new RFC3339DateFormat())
                       .addModule(new JavaTimeModule())
                       .addModule(new JsonNullableModule())
                       .build();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client: Java Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants