I have JSON looking like this, let say Question
{
"type": "String",
"value": "{\"text\":\"Question\",\"type\":\"predefined\",\"parameter\":\"param1\",\"answers\":[\"Answer1\",\"Answer2\",\"Answer3\",\"Answear4\"]}",
"valueInfo": {}
}
and i want to parse it with Jackson to Question objecti with object Value inside contains details about question (like text, type, and a list of answers)
i try to create classes Question and Value
public class AbasQuestion {
@JsonProperty("type")
String type;
@JsonProperty("value")
Value value;
JsonNode valueInfo;
}
public class Value {
String text;
String type;
String parameter;
List<String> answers;
}
and parse string to them with
Question question = objectMapper.readValue(jsonQuestion, Question.class);
but stil i get error
Can not instantiate value of type [simple type, class Value] from String value; no single-String constructor/factory method (through reference chain: Question["value"])
I understan that Value is String and i have to convert it to Value object but how and wher ? inside Value constructor or inside Question setter ? to Jackson could do map it.