MapStruct with XSI Type mapping

185 Views Asked by At

I am new to map struct. I am try to convert JSON to XML. My XML component looking for XSI type. I have done the custom mapping with the cast the XSI type object. But the XML is missing the XSI type. which is leading in the sub systems.

default com.test.sales.types.Order map(com.test.order.types.Order value) {
    if (value != null) {
        com.test.sales.types.Order mapping = null;
        if (value instanceof com.test.order.types.X)
            mapping = map((com.test.order.types.X) value);
        else if (value instanceof com.test.order.types.Y)
            mapping = map((com.test.order.types.Y) value);
        return mapping;
    }
    return null;
};
1

There are 1 best solutions below

0
On

It is working fine if you set the object on the root element object.

default com.test.sales.types.X mapX(com.test.order.types.Order value) {
    com.test.sales.types.Order mapping = 
        mapping = map((com.test.order.types.X) value);
    return mapping;

};

default com.test.sales.types.Y mapY(com.test.order.types.Order value) {
    com.test.sales.types.Order mapping = 
        mapping = map((com.test.order.types.Y) value);
    return mapping;

};

default com.test.sales.types.Sales map(com.test.order.types.Sales data) {
com.test.sales.types.Sales returns = new com.test.sales.types.Sales();


if (data.getOrder().getIsXObj()) {
returns.setOrder(mapX(data.getOrder()));

} else {

returns.setOrder(mapY(data.getOrder()));

} }