Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 推土机:成功转换后用源值覆盖的字段_Java_Spring_Mapping_Javabeans_Dozer - Fatal编程技术网

Java 推土机:成功转换后用源值覆盖的字段

Java 推土机:成功转换后用源值覆盖的字段,java,spring,mapping,javabeans,dozer,Java,Spring,Mapping,Javabeans,Dozer,我在使用推土机时遇到了一种非常奇怪的行为。我有一个复杂的类型,有两个属性需要合并成一个字符串,没有什么疯狂的 这是我的转换器: @Component public class CatalogEntryRequestRDToStringConverter extends DozerConverter<CatalogEntryRequestRD, String> { public CatalogEntryRequestRDToStringConverter() {

我在使用推土机时遇到了一种非常奇怪的行为。我有一个复杂的类型,有两个属性需要合并成一个字符串,没有什么疯狂的

这是我的转换器:

@Component
public class CatalogEntryRequestRDToStringConverter extends DozerConverter<CatalogEntryRequestRD, String> {

    public CatalogEntryRequestRDToStringConverter() {
        super(CatalogEntryRequestRD.class, String.class);
    }

    public CatalogEntryRequestRDToStringConverter(Class<CatalogEntryRequestRD> prototypeA, Class<String> prototypeB) {
        super(prototypeA, prototypeB);
    }

    @Override
    public String convertTo(CatalogEntryRequestRD source, String destination) {
        if (source != null) {
            return ConverterUtil.concatenateCodeAndVersion(getParameter(), source.getCode(), source.getVersion());
        }
        return null;
    }

    @Override
    public CatalogEntryRequestRD convertFrom(String source, CatalogEntryRequestRD destination) {
        return null;
    }
转换器工作。调用正确,转换成功。然而,在一些调试之后,我注意到在映射过程结束时再次调用目标字段的set方法,其值为CatalogEntryRequestRD的toString()方法。因此,正确转换的字段将被source.toString()覆盖。它猜测这一定与推土机如何创建要映射的字段列表有关

有人经历过这样的事情吗


提前感谢

我不确定这是否是问题所在,但它可能与通配符映射有关。在映射规范中,是否可以添加TypeMappingOptions.wildcard(false)并查看它是如何改变的?不确定这是问题所在,但可能与通配符映射有关。在映射规范中,可以添加TypeMappingOptions.wildcard(false)并查看它是如何改变的吗?
mapping(StartBorderRequest.class, StartBorderRequestMessageType.class)
        .fields("request.scopeModifiers", "scopeModifiers")
        .fields("request.collectedData", "collectedData")
        .fields("request.selectedResponseData", "selectedResponseData");


mapping(com.test.types.CollectedDataRequestType.class, com.test.message.CollectedDataRequestType.class)
    .fields("tcnType", "tcnType", fieldMappingBuilder -> {
        fieldMappingBuilder.customConverter("CatalogEntryRequestRDToStringConverter");
        fieldMappingBuilder.customConverterParam("tcnTypeId");
    });