FasterXML / jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Apache License 2.0
3.52k stars 1.38k forks source link

Improve creator exceptions #3153

Open xenoterracide opened 3 years ago

xenoterracide commented 3 years ago

I already figured this out, but it took hours when it could have taken minutes. The issue wasn't very googleable, as most results don't even say that you can do constructor injection without @JsonProperty, and the others are using spring-boot and don't mention that you need to register ParameterNamesModule.

The first error message, without @JsonCreator is annoying because it's something like "Unable to find Creator" blah blah, "no default constructor" blah blah. I suspect it could find its way to the next exception if it checked that I only had one constructor with arguments. That might be hard though, so I forgive it. At least it might help to suggest annotating with @JsonCreator in that message.

When you do annotate with that, the message seems like a lie

Argument #0 has no property name, is not Injectable: can not use as Creator

I realize reading this now that it means that it has no @JsonProperty, I originally assumed that it meant that the parameter name was missing, and thus I didn't have -parameters which didn't make sense. The simplest solution in my mind would be to expand this message to say something like

Argument #0 has no property name, is not Injectable: can not use as Creator. Add @JsonProperty or compile with -parameters and register ParameterNamesModule

 ./gradlew -q :config-loader:yaml:dependencyInsight --configuration runtimeClasspath --dependency jackson-core                                                                                                     # brix -> ccushing/copy-5
com.fasterxml.jackson.core:jackson-core:2.11.4
   variant "runtime" [
      org.gradle.status              = release (not requested)
      org.gradle.usage               = java-runtime
      org.gradle.libraryelements     = jar
      org.gradle.category            = library

      Requested attributes not found in the selected variant:
         org.gradle.dependency.bundling = external
         org.gradle.jvm.environment     = standard-jvm
         org.gradle.jvm.version         = 11
   ]
   Selection reasons:
      - By constraint : dependency was locked to version '2.11.4'
      - By ancestor

com.fasterxml.jackson.core:jackson-core:{strictly 2.11.4} -> 2.11.4
\--- runtimeClasspath

com.fasterxml.jackson.core:jackson-core:2.11.4
+--- com.fasterxml.jackson.core:jackson-databind:2.11.4
|    +--- runtimeClasspath (requested com.fasterxml.jackson.core:jackson-databind)
|    +--- project :config-loader:spi (requested com.fasterxml.jackson.core:jackson-databind)
|    |    \--- runtimeClasspath
|    +--- project :config-loader:api (requested com.fasterxml.jackson.core:jackson-databind)
|    |    +--- runtimeClasspath
|    |    \--- project :config-loader:spi (*)
|    +--- org.springframework.boot:spring-boot-starter-parent:2.4.5
|    |    +--- runtimeClasspath (requested org.springframework.boot:spring-boot-starter-parent:2.+)
|    |    +--- project :config-loader:spi (requested org.springframework.boot:spring-boot-starter-parent:2.+) (*)
|    |    +--- project :config-loader:api (requested org.springframework.boot:spring-boot-starter-parent:2.+) (*)
|    |    \--- project :cli:api (requested org.springframework.boot:spring-boot-starter-parent:2.+)
|    |         +--- runtimeClasspath
|    |         \--- project :config-loader:spi (*)
|    +--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.11.4
|    |    +--- runtimeClasspath (requested com.fasterxml.jackson.dataformat:jackson-dataformat-yaml)
|    |    \--- org.springframework.boot:spring-boot-starter-parent:2.4.5 (*)
|    \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.4
|         +--- runtimeClasspath (requested com.fasterxml.jackson.module:jackson-module-parameter-names)
|         \--- org.springframework.boot:spring-boot-starter-parent:2.4.5 (*)
+--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.11.4 (*)
+--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.4 (*)
\--- org.springframework.boot:spring-boot-starter-parent:2.4.5 (*)

com.fasterxml.jackson.core:jackson-core -> 2.11.4
\--- runtimeClasspath

(*) - dependencies omitted (listed previously)

A web-based, searchable dependency report is available by adding the --scan option.
cowtowncoder commented 3 years ago

Improving exception messages would be great. Will leave here in case someone has time and itch to work on this! I may be able to do something for this whenever I get a chance to work on introspection changes for 2.13, but targeted changes might be easier.

cowtowncoder commented 3 years ago

Introspection rewrite did not get in 2.13. :-(