eclipse-ee4j / eclipse-ee4j/yasson
JsonbDeserializer deserializes JSON array into class java.lang.String
- Dominant language
- Java
- Stars
- 218
- Forks
- 109
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 9
Description
**Describe the bug**
Hello,
After changing yasson version to 3.0.3 JsonbDeserializer started to allow deserializing JSON array into String by taking last value from array and ignoring the rest of the values.
**To Reproduce**
Steps to reproduce the bug
I am trying to deserialize json:
```
{
"test": [
"data1",
"data2",
"data3",
"data4"
]
}
```
into:
```
public class ExampleRequest {
private String test;
}
```
with the following code:
```
Jsonb jsonb = JsonbBuilder.create(new JsonbConfig()
.withFormatting(true)
.withNullValues(true));
String jsonString = "{\n"
+ " \"test\": [\n"
+ " \"data1\",\n"
+ " \"data2\",\n"
+ " \"data3\",\n"
+ " \"data4\"\n"
+ " ]\n"
+ "}";
ExampleRequest er = jsonb.fromJson(jsonString, ExampleRequest.class);
```
with yasson version **2.0.4** exception is thrown:
`jakarta.json.bind.JsonbException: Unable to deserialize property 'test' because of: Can't deserialize JSON array into: class java.lang.String
`
with yasson version **3.0.3** during the deserialisation no exception is thrown and instead last value from that array is taken to initialize ExampleRequest:
`ExampleRequest(test=data4)
`
**Expected behavior**
Throw an exception
**System information:**
- OS: Mac
- Java Version: 17
- Yasson Version: 3.0.3 (but problem occurs since 3.0.0-RC2)
Contributor guide
Assessment
This issue has not been assessed yet.