Please suggest the best solution. There is the following xml file
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
<CD>
<TITLE>Greatest Hits</TITLE>
<ARTIST>Dolly Parton</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>RCA</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1982</YEAR>
</CD>
<CD>
<TITLE>Still got the blues</TITLE>
<ARTIST>Gary Moore</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Virgin records</COMPANY>
<PRICE>10.20</PRICE>
<YEAR>1990</YEAR>
</CD>
<CD>
<TITLE>Eros</TITLE>
<ARTIST>Eros Ramazzotti</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>BMG</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1997</YEAR>
</CD>
<CD>
<TITLE>One night only</TITLE>
<ARTIST>Bee Gees</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Polydor</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1998</YEAR>
</CD>
</CATALOG>
also have 5 classes: Catalog, Cd, Album, Artist, Country, Registry
How can i get object of Registry with filled fields:
public class Registry {
private List<Country> countries = new ArrayList<>();
}
public class Country {
private String name; // <COUNTRY>...</COUNTRY>
private List<Artist> artists = new ArrayList<>();
}
public class Artist {
private String name; // <ARTIST>...</ARTIST>
private List<Album> albums = new ArrayList<>();
}
public class Album {
private String name; // <TITLE>...</TITLE>
private int year; // <YEAR>...</YEAR>
}
And
- public class Catalog {
-
@JacksonXmlProperty(localName = "CD") -
@JacksonXmlElementWrapper(useWrapping = false) - private List cds;
- public List getCds() {
- return cds;
-
} - }
- public class Cd {
-
@JsonProperty("TITLE") // Album name - private String title;
-
@JsonProperty("ARTIST") // Artist name - private String artist;
-
@JsonProperty("COUNTRY") // Country name - private String country;
-
@JsonProperty("COMPANY") - private String company;
-
@JsonProperty("PRICE") - private double price;
-
@JsonProperty("YEAR") // Album year - private int year;
- }