The following code serializes as expected, but exception occurs while deserialization
public class Main {
public static void main(String[] args) throws IOException {
ObjectMapper mapper = new XmlMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
DialogConfig test = new DialogConfig(
List.of(
new Case("awdawd", "Adwawd"),
new Case("agtt", "hyyhy")
)
);
mapper.writeValue(new File("test-write.xml"), test); // OK
try {
DialogConfig config = mapper.readValue(new File("test-read.xml"), DialogConfig.class); // Exception Trown
System.out.println(config.cases());
}catch (Exception e){
System.out.println(e.getMessage());
}
}
}
record DialogConfig(
@JacksonXmlProperty(localName = "case")
@JacksonXmlElementWrapper(localName = "cases")
List<Case> cases
) {
}
record Case(
@JacksonXmlProperty(isAttribute = true, localName = "answer") String answer,
@JacksonXmlProperty(isAttribute = true, localName = "point") String point
) {
}
Error Message – Invalid definition for property ‘cases’ (of type DialogConfig
): Could not find creator property with name ‘cases’ (known Creator properties: [case])
at [Source: (File); line: 1, column: 1]
If I remove both annotations from cases List property Error disappears