简体   繁体   中英

MapStruct with XSI Type mapping

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;
};

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()));

} }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM