eclipse-ee4j / eclipse-ee4j/yasson
JSON Binding Specification violation on toJson() API
- Dominant language
- Java
- Stars
- 218
- Forks
- 109
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 9
Description
**Describe the bug**
As per Jakarta 9 JSON Binding specification document, https://jakarta.ee/specifications/jsonb/2.0/apidocs/jakarta/json/bind/jsonb#:~:text=is%20null.-,toJson,JSON%20Binding%201.0,-toJson, toJson() methods do not accept any of the parameters as null. But as per our findings recorded in https://github.com/eclipse-lsp4jakarta/lsp4jakarta/issues/642, it clearly accepts the null parameter instead of throwing the NullPointerException. This is in violation with the documentation.
**To Reproduce**
1. Create a simple java project which uses toJson() API from Jakarta JsonB module, and run it. Eg: https://github.com/user-attachments/files/26398583/JsonbFromToJson.java
**Expected behavior**
To throw NullPointerException as per https://jakarta.ee/specifications/jsonb/2.0/apidocs/jakarta/json/bind/jsonb#:~:text=is%20null.-,toJson,JSON%20Binding%201.0,-toJson
**Observed Behavior**
The output for the sample attached are as below. It prints the null value instead of throwing the error.
```
To JSON Results:
Result: null
{"age":25,"name":"Bob"}
Two: {"age":25,"name":"Bob"}null
{"age":25,"name":"Bob"}null["apple","banana","cherry"]
Three: {"age":25,"name":"Bob"}null["apple","banana","cherry"]null
```
**System information:**
- OS: Mac
- Java Version: 17
- Yasson Version: 2.0.4
**Additional context**
More details about the issue to be found in https://github.com/eclipse-lsp4jakarta/lsp4jakarta/issues/642.
Contributor guide
Assessment
This issue has not been assessed yet.