Here's how you can convert your XML string to Java objects or POJO classes, we will be using the converter and built in libraries like 'com.fasterxml.jackson.dataformat' to parse our object.
The XML string should be correctly formatted before converting it to Java classes.
Here's an example of an XML string:
You can optionally choose from the settings to:
When you copy the returned classes in the directory of your solution, you can deserialize your XML string or file using the 'Root' class as mentioned in commented example below:
Here are the classes returned from the previous example:
public class additionalCosts {
public String value;
public String currency;
public String marketingType;
public String priceIntervalType;
}
public class realestates {
public String externalId;
public String title;
public String creationDate;
public String lastModificationDate;
public String thermalCharacteristic;
public String energyConsumptionContainsWarmWater;
public String buildingEnergyRatingType;
public String additionalArea;
public String numberOfFloors;
public additionalCosts additionalCosts;
}
This is how can you deserialize your XML string in your Java code:
First, import the 'com.fasterxml.jackson.dataformat' into our pom.xml
Second, use the 'XMLMapper' class and call the 'readValue' method by supplying it the xml string and root class
XmlMapper xmlMapper = new XmlMapper();
realestates value = xmlMapper.readValue("", realestates.class);