I am trying to map a SOAP request to a Java POJO using org.modelmapper.ModelMapper
But, its not working due to the structure of the source, it has a list of strings ....
Below is the snippet for the 3 main components source soap message, destination DTO Java POJO and the service endpoint mapping logic.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "EventRequestBodyType", propOrder = {
"content"
})
public class EventRequestBodyType {
@XmlElementRefs({
@XmlElementRef(name = "field1", namespace = "http://x.y.z.event", type = JAXBElement.class, required = false),
@XmlElementRef(name = "field2", namespace = "http://x.y.z.event", type = JAXBElement.class, required = false),
@XmlElementRef(name = "field3", namespace = "http://x.y.z.event", type = JAXBElement.class, required = false),
@XmlElementRef(name = "field4", namespace = "http://x.y.z.event", type = JAXBElement.class, required = false),
@XmlElementRef(name = "field5", namespace = "http://x.y.z.event", type = JAXBElement.class, required = false)
})
protected List<JAXBElement<? extends Serializable>> content;
/**
* Gets the rest of the content model.
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link BigInteger }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
*
*
*/
public List<JAXBElement<? extends Serializable>> getContent() {
if (content == null) {
content = new ArrayList<JAXBElement<? extends Serializable>>();
}
return this.content;
}
}
This is the POJO (What i am trying to map to)
import lombok.Data;
@Data
public class EventDTO {
private String field1;
private String field2;
private String field3;
private String field4;
private String field5;
}
Below is the code snippet in my service, doing the mapping:
if(null!= soapEventRequest.getRequestBody()) {
EventRequestBodyType eventRequestBodyType =
soapEventRequest.getRequestBody();
EventDTO event = modelMapper.map(eventRequestBodyType,EventDTO.class);
eventBody.setEventRegisterAssessment(event);
}
How do I map my EventDTO to the 5 fields returned in the EventRequestBodyType.getContent(). Any ideas will be welcomed. I donor have to use RoleMapper library, any approach or suggestions is welcomed. Thanks in advance