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.
I've checked previous yasson versions and this problem started to occur since 3.0.0-RC2.
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)