Hi
I am trying to do xml to pojo deserialization.
My xml looks like below
<?xml version="1.0" encoding="UTF-8"?>
<Photo id="xyq3994">
<Sizes>
</Sizes>
</Photo>
</DataApi>
I have written pojo classes for the same
@Getter
@Setter
public class DataApi {
private Photo photo;
}
@Getter
@Setter
public class Photo {
private Sizes sizes;
private String id;
}
@Getter
@Setter
public class Sizes {
private List<Size> size;
}
@Getter
@Setter
public class Size {
private String id;
private String url;
}
My mapper looks like below:
public static Object getResponseXML(String responseString, Class responseClass) throws IOException {
ObjectMapper xmlMapper = new XmlMapper();
xmlMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
return xmlMapper.readValue(responseString, responseClass);
}
@Test
public void test() {
DataApi dataApi= (DataApi) getResponseXML(response.asString(), DataApi.class);
dataApi. getPhoto().getSizes().getSize().get(0);
}
I am getting IndexOutOfBoundException. And the list is not mapped to size on deserialization.
Can someone pls guide me what am I missing here.
I am using 2.12.2 version com.fasterxml.jackson
Regards,
Aswathy