eclipse-ee4j / eclipse-ee4j/yasson
@JsonbProperty("propertyName") is not respecting new JsonbConfig().withNullValues(true)
- Dominant language
- Java
- Stars
- 218
- Forks
- 109
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 9
Description
Hi there,
I just ran into an issue wich took me some time to debug. As of my opinion, this is not the expected behavior:
### Steps to reproduce:
1. Create a Class with a property and annotate it with `@JsonbProperty("propertyName")`
2. Initialize an Instance of that class with a null value in that property
3. Initialize a JSON-B Mapper with a custom config: `new JsonbConfig().withNullValues(true)`
4. Serialize the object
This issue occurred using yasson 1.0.5
### Expected outcome:
Object is serialized with the property included and value `null`.
### Actual outcome:
Object is serialized without the property.
### One step further:
5. Remove the `@JsonbProperty("propertyName")` from the field
6. Serialize again and watch the property appearing in the serialized json
As I debugged though the code of Yasson, I came across the reason why this behavior shows up:
The Annotation `@JsonbProperty` has a property `nillable` with the default value being `false`
Although I would rather expect the default value being `null` and to respect the global configuration when omitting the annotation parameter, I see that this would be a breaking change. Instead I would suggest to add a new Annotation like `@JsonbPropertyName` with only the property name being possible to customize.
**Please advise if this behavior is known and if so what could be a mitigation.**
Kind regards,
Yannick
Contributor guide
Research direction
Reproduce the issue with a class using @JsonbProperty("propertyName"), a null property, and new JsonbConfig().withNullValues(true), then compare serialization with and without the annotation. Inspect Yasson's handling of the annotation's nillable default and determine a compatible behavior or API change; done means the annotated property is serialized as null under the stated configuration, with coverage for the reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100