I have used Jackson before to convert JSON to POJO and that works fine, now I am trying to do it with XML and I have having difficulties.
I have the following code:
ObjectMapper xmlMapper = new XmlMapper();
GoodreadsResponse response = xmlMapper.readValue("<GoodreadsResponse><Request><authentication>true</authentication></Request><book><id>6465707</id></book></GoodreadsResponse>", GoodreadsResponse.class);
System.out.println(response);
GoodreadsResponse.java
@JacksonXmlRootElement(localName = "GoodreadsResponse")
public class GoodreadsResponse {
@JacksonXmlProperty(localName = "book")
private Book book;
public Book getBook() { return book; }
}
Book.java
public class Book {
@JacksonXmlProperty(localName = "id")
private String id;
public String getId() { return id; }
}
Whatever I do I cannot get it working, I am not sure if my classes are correct or not.
Can someone have a look and see if they can point me in the right direction.
Thanks
No comments:
Post a Comment