Using java and GSON, I want to deserialize my POJO class
@Data
public class Book {
@SerializedName("id")
private String id;
@SerializedName("tags")
private List<String> tags;
}
gson.fromJson(userRecordString, Book.class)
from a mailformed JSON, which I receive from the Kinesis stream:
{
"id": "B09W1W4D2F",
"tags": "[TAG_1,TAG_2]"
}
The problem here is I receive "[TAG_1,TAG_2]"
with quotes, so JSON threats it as a String, not as an array. It should be "tags": ["TAG_1","TAG_2"]
instead.
I’m assuming I need to write a custom deserealizer, but all the solutions I found are based on creating a new class for private List. I don’t want to do it.
I want to:
- store my deserialized values in
List<String> tags
- preferably deserialize other fields using default serialization, so I don’t want to deserialize the whole class manually.
Is there any solution to this?