jakartaee / jakartaee/jsonb-api
Clarification needed
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
Issue from @maald moved over from Yasson repo at: https://github.com/eclipse-ee4j/yasson/issues/407
Assume you have a class with 2 properties
```java
public class Whatever {
public int numberProp;
public String stringProp; // String
}
```
Serialize an instance to JSON
```java
Whatever obj = new Whatever();
obj.numberProp = 1;
obj.stringProp = "hello";
String json = JsonbBuilder.create().toJson(obj);
System.out.println(json);
```
as expected you get something like this
```json
{
"numberProp" : 1,
"stringProp" : "hello"
}
```
Now, if you de-serialize the following JSON payload
```json
{
"numberProp" : 1,
"stringProp" : 12345
}
```
Json-b will simply de-serialize a JSON number value (12345) to a Java String ("12345")!
In that payload, "stringProp" clearly has a JSON number value/not a JSON string value.
The confusing part here is that Json-B serializes Java String to JSON string by making sure to include quotes but then de-serialize a JSON number (has no quotes) to Java String.
Is this a bug or the expected behavior?
Personally, I prefer fail-fast approach (let the client know there is an issue with the value/expected a JSON string) instead of masking this basic type mismatch.
Contributor guide
Research direction
Start by reading the linked Yasson issue and the JSON-B behavior described here. No source file or test is named, so first determine where this deserialization rule is specified or implemented. Done means establishing whether numeric-to-String conversion is expected and recording the resulting behavior or required change clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100