gpt4 book ai didi

Java UOM java.lang.NoSuchFieldError : ONE

转载 作者:行者123 更新时间:2023-12-02 11:09:20 27 4
gpt4 key购买 nike

我遇到了 Java 测量单位 (UOM) 的版本困惑问题。我有一个

import tec.uom.se.AbstractUnit;

public class Class0 {
/**
* Is an {@link AbstractUnit} in order to be serializable as {@code @Basic}
* with JPA.
*/
private AbstractUnit<?> unit;

public Class0() {
}

public Class0(AbstractUnit<?> unit) {
this.unit = unit;
}

public AbstractUnit<?> getUnit() {
return unit;
}

public void setUnit(AbstractUnit<?> unit) {
this.unit = unit;
}
}

我正在序列化

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.opower.unitsofmeasure.UnitJacksonModule;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import tec.uom.se.AbstractUnit;
import static tec.uom.se.unit.Units.SQUARE_METRE;

public class TheTest {

@Test
public void test() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new UnitJacksonModule());
Class0 value = new Class0((AbstractUnit) SQUARE_METRE);
String json = objectMapper.writeValueAsString(value);
assertEquals("m²", json);
}
}

使用时

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.opower.unitsofmeasure</groupId>
<artifactId>jackson-module-unitsofmeasure</artifactId>
<version>1.3.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>tec.uom</groupId>
<artifactId>uom-se</artifactId>
<version>1.0.9</version>
<type>jar</type>
</dependency>

失败的原因是

java.lang.NoSuchFieldError: ONE
at systems.uom.ucum.UCUM.<clinit>(UCUM.java:114)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at tec.uom.se.format.SymbolMap.<init>(SymbolMap.java:115)
at tec.uom.se.format.SymbolMap.of(SymbolMap.java:142)
at systems.uom.ucum.format.UCUMFormat$Parsing.<clinit>(UCUMFormat.java:416)
at systems.uom.ucum.format.UCUMFormat.getInstance(UCUMFormat.java:106)
at com.opower.unitsofmeasure.UnitJacksonModule$UnitJsonSerializer.serialize(UnitJacksonModule.java:56)
at com.opower.unitsofmeasure.UnitJacksonModule$UnitJsonSerializer.serialize(UnitJacksonModule.java:42)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3893)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3207)
at de.richtercloud.jackson.unit.serialization.TheTest.test(TheTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

对于我来说失败的原因并不明显,我怀疑版本或实现冲突。

最佳答案

通过切换到来修复此问题

<dependency>
<groupId>tec.uom</groupId>
<artifactId>uom-se</artifactId>
<version>1.0.8</version>
</dependency>

关于Java UOM java.lang.NoSuchFieldError : ONE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50709930/

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