-
Notifications
You must be signed in to change notification settings - Fork 175
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
Jackson skips isXXX properties with Int type #337
Comments
@imanushin thanks for your contribution. Workaround for you case is: private data class Problematic(val id: Int, @get:JsonProperty("isDefault") val isDefault: Int) @cowtowncoder the problem related to #80. Based on Kotlin docs:
The current implementation doesn't take into account a case where a property has a non-boolean type. At this point, |
Yeah to me using "is-getter" for non-boolean values seems kind of wrong, but I know Kotlin specifies that as legit use case. I changed handling in 2.11 to be more configurable, but it is probably true that addition of But basically I would not object to having a setting to enable discovery of "other kinds" of is-getters. |
@cowtowncoder adding this feature makes sense because for java it doesn't work also: public class Github337Java {
/* com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
No serializer found for class com.fasterxml.jackson.module.kotlin.test.github.Correct and no properties discovered to create BeanSerializer
(to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) */
@Test
public void serialization() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
String value = mapper.writeValueAsString(new Correct());
assertNotNull(value);
}
}
class Correct {
private final Integer def = 1;
public Integer isDef() {
return def;
}
} |
Yes, but my understanding is that Bean specification would only consider boolean/Boolean valued is getters. But if you or anyone else have link(s) to different interpretation would be happy to be proven wrong? But even if so, I guess I am not totally against detecting non-boolean-valued is-getters. Change could expose previously unseen properties, if changed for default handling so there's minor backwards compatibility concern. |
Based on Java Beans specification (8.3 Design Patterns for Properties) Have you ever had a request for such a feature in Jackson for Java/Scala? |
@viartemev I do not remember having this request for Java or Scala. The reason I mention I am open to other styles of configuration and if refactoring in Unfortunately I haven't had time to dig deeper into this issue, so help would be appreciated. |
I added some failing tests, and one working test that shows @viartemev 's workaround using use-site targets. |
This issue will be fixed by #630 and therefore closed as a duplicate. |
Describe the bug
The Kotlin properties with signature
isXXX: Int
omits default values even with optionJsonInclude.Include.ALWAYS
To Reproduce
mapper.writeValueAsString(...)
Expected behavior
Both classes have the same result semantic, so jsons are like this:
{id: 1, default: 0}
{id: 1, isDefault: 0}
Actual result
isDefault
is ignored when it has0
:{id: 1, default: 0}
{id: 1}
<--- 0 is ignored for Int typeVersions
Kotlin: 1.3.72
Jackson-module-kotlin: 2.11
Jackson-databind: 2.11
Additional context
This is issue of 2.11 only. I didn't see it with previous versions (2.10.1 - 2.10.4). Version downgrading helps.
Spring Boots also adds his dependencies. Probably, this is result of version conflict. Actual runtime dependencies are:
The text was updated successfully, but these errors were encountered: