-
-
Notifications
You must be signed in to change notification settings - Fork 335
Add OptBoolean
valued @JsonProperty.isRequired
to (eventually) replace @JsonProperty.required
#284
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
Comments
I am at Spring Boot 3.4.5 and now I can't serialize classes anymore since 2.19. For all TOs with use of Exception in thread "main" java.lang.NoSuchMethodError: 'com.fasterxml.jackson.annotation.OptBoolean com.fasterxml.jackson.annotation.JsonProperty.isRequired()'Exception in thread "main" java.lang.NoSuchMethodError: 'com.fasterxml.jackson.annotation.OptBoolean com.fasterxml.jackson.annotation.JsonProperty.isRequired()' The TOs do not use Reproducer: pom.xml <dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.19.0</version>
</dependency>
Code: import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
val specTO = TestTO(
someProperty = "hello"
)
val json = jacksonObjectMapper().writeValueAsString(specTO) // EXCEPTION
data class TestTO (
@get:JsonProperty()
val someProperty: String? = null
) |
@spyro2000 you must have matching minor versions: if -- for example, you upgrade to Kotlin module 2.19.0, you must also have 2.19 (or higher) version of:
from exception it seems the last is not the case. One good way to keep versions aligned is to depend on |
Hi @cowtowncoder, thank you for your response :) <dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.19.0</version>
</dependency> with <dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.19.0</version>
</dependency> ? Or should I remove the version for <dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.19.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<!-- ... -->
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-bom</artifactId>
</dependency> ? Or should I remove the version alltogether (that's what helped for me at the moment, at least within a Spring project) |
You should import
With Spring you may already be using its bom, but that has likely some older Jackson version as managed dependency. |
Ok, thank you. Indeed it worked again after I just removed the version from |
Yeah, these days frameworks set managed dependency versions to try to keep things consistent. |
One nasty issue with
@JsonProperty
annotation is that itsrequired
property isboolean
-valued: and as such cannot indicate "use defaults" / "not defined" option -- and default beingfalse
, it means that:is same as
so that it is easy to accidentally specify that a property is NOT required. This is especially true when considering cases where there are more generic defaults (provided by modules, f.ex) at, levels like:
in which case any use of
@JsonProperty
either:required = true
case considered explicit, is impossible to disable "required-ness"What we need, really, is third state: and use of
OptBoolean
enum offers that: it has 3 values:TRUE
(->Boolean.TRUE
)FALSE
(->Boolean.FALSE
)DEFAULT
(->null
)However. We cannot really change type of
required
property, even with 2.x->3.0 transition -- because we do want to keepjackson-annotations
backwards-compatible (in thatjackson-annotations
2.x versions will work with 3.x, and (for most purposes) vice-versa).What we can do is to:
OptBoolean
valueisRequired
(higher precedence) and oldrequired
(lower precedence) via databindAnnotationIntrospector
required
as Deprecated (... and possibly later 2.x, but not in 2.19)This issue is for addition of the new property: there will be new
jackson-databind
ticket for reminder of work.The text was updated successfully, but these errors were encountered: