gpt4 book ai didi

java - 当我将 Java 版本升级到 openJDK 11 时,加载模型映射器配置时出现 nullpointerException

转载 作者:行者123 更新时间:2023-12-01 14:33:30 24 4
gpt4 key购买 nike

将 Java 版本升级到 openJDK 11 后,modelMapper 配置未加载,出现 NullPointerException。

NullPointerException issue is not resolved even after upgrading modelMapper version to 2.3.2

错误日志:

1) 配置映射失败

堆栈跟踪:

at org.modelmapper.internal.Errors.throwConfigurationExceptionIfErrorsExist(Errors.java:241)
at org.modelmapper.internal.ExplicitMappingBuilder.build(ExplicitMappingBuilder.java:244)
at org.modelmapper.internal.ExplicitMappingBuilder.build(ExplicitMappingBuilder.java:96)
at org.modelmapper.internal.TypeMapImpl.addMappings(TypeMapImpl.java:92)
at org.modelmapper.internal.TypeMapStore.getOrCreate(TypeMapStore.java:124)
at org.modelmapper.ModelMapper.addMappings(ModelMapper.java:113)
...
Caused by: java.lang.NullPointerException
at org.modelmapper.internal.ExplicitMappingBuilder$ExplicitMappingInterceptor.access$000(ExplicitMappingBuilder.java:304)
at org.modelmapper.internal.ExplicitMappingBuilder.createAccessorProxies(ExplicitMappingBuilder.java:287)
at org.modelmapper.internal.ExplicitMappingBuilder.createProxies(ExplicitMappingBuilder.java:277)
at org.modelmapper.internal.ExplicitMappingBuilder.visitPropertyMap(ExplicitMappingBuilder.java:266)
at org.modelmapper.PropertyMap.configure(PropertyMap.java:386)
at jdk.internal.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.modelmapper.internal.ExplicitMappingBuilder.build(ExplicitMappingBuilder.java:227)
... 6 more

最佳答案

在 ByteBuddy 内部抛出一个导致问题的异常,我将进一步调查它是否可能是 ModelMapper 中的错误。

无论如何,请在 http://modelmapper.org/user-manual/property-mapping/ 查看 Java 8 选项卡,您当前的代码似乎使用的是旧文档。

ModelMapper mm = new ModelMapper();

TypeMap<A, B> typeMap = mm.createTypeMap(A.class, B.class);
typeMap.addMappings(mapper -> {
mapper.map(A::getDate, B::setTest);
... // Other mappings
});

这可以立即转换 Date -> Long 而无需任何其他配置。如果你想进一步配置它,你总是可以像这样创建自定义转换器:

Converter<Date, Long> dateToLong = new AbstractConverter<Date, Long>() {
@Override
protected Long convert(Date source) {
System.out.println("converting: " + source + " to " + source.getTime());
return source.getTime();
}
};

typeMap.addMappings(mapper -> mapper.using(dateToLong).map(A::getDate, B::setTest));

关于java - 当我将 Java 版本升级到 openJDK 11 时,加载模型映射器配置时出现 nullpointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56806605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com