首页 > 解决方案 > MapStruct 与 XSI 类型映射

问题描述

我是地图结构的新手。我正在尝试将 JSON 转换为 XML。我的 XML 组件正在寻找 XSI 类型。我已经使用强制转换 XSI 类型对象完成了自定义映射。但是 XML 缺少 XSI 类型。在子系统中处于领先地位。

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

标签: mappingmapstructxsitype

解决方案


如果您在根元素对象上设置对象,它工作正常。

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

} 别的 {

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

} }


推荐阅读