I’m trying to deserialize following xml
<fightrules>
<fightrule id="1" owner="player" name="Переопределение разрешения открывать огонь #1"/>
<fightrule id="2" owner="player" name="Ксеноны">
<setting faction="xenon" civilian="engage"/>
</fightrule>
</fightrules>
And using such definition
@Data
public class Fightrules {
public List<Fightrule> fightrule;
@Data
@JsonAutoDetect
public static class Fightrule {
public int id;
public String owner;
public String name;
@JacksonXmlElementWrapper(useWrapping = false)
public List<Setting> setting;
}
}
@Data
public class Setting {
@JacksonXmlProperty(isAttribute = true)
public String faction;
@JacksonXmlProperty(isAttribute = true)
public String civilian;
}
However I get an exception
Unrecognized field "faction" (class Fightrules$Fightrule), not marked as ignorable
Seems like Jackson doesn’t see nested object list and tries to serialize it to Fightrules object.
I’ve tried to use annotations that helps Jackson resolving this kind of situation but none of them fitted. But I suppose there should be workaround. Maybe the problem in structure of xml because Setting object is optional