gpt4 book ai didi

java - UnrecognizedPropertyException 无法识别的字段 "resourceType"?

转载 作者:行者123 更新时间:2023-12-01 22:31:05 25 4
gpt4 key购买 nike

嗨,我想将我的 JSON 对象存储在商店中,我想使用 Jackson mapper 来读取该对象,但是在运行程序时它会抛出

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "resourceType" (Class io.github.semr.proflr.api.entity.Profile), not marked as ignorable
at [Source: java.io.FileInputStream@46ef0a4f; line: 2, column: 18] (through reference chain: io.github.semr.proflr.api.entity.Profile["resourceType"])
at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1909)
at io.github.semr.proflr.impl.ProfileImpl.add(ProfileImpl.java:41)
at io.github.semr.proflr.impl.ProfileImpl.start(ProfileImpl.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.dm.InvocationUtil.invokeMethod(InvocationUtil.java:111)
at org.apache.felix.dm.InvocationUtil.invokeCallbackMethod(InvocationUtil.java:66)
at org.apache.felix.dm.impl.ComponentImpl.invokeCallbackMethod(ComponentImpl.java:688)
at org.apache.felix.dm.impl.ComponentImpl.invoke(ComponentImpl.java:679)
at org.apache.felix.dm.impl.ComponentImpl.bindService(ComponentImpl.java:624)
at org.apache.felix.dm.impl.ComponentImpl.access$400(ComponentImpl.java:52)
at org.apache.felix.dm.impl.ComponentImpl$7.run(ComponentImpl.java:181)
at org.apache.felix.dm.impl.SerialExecutor$1.run(SerialExecutor.java:47)
at org.apache.felix.dm.impl.SerialExecutor.scheduleNext(SerialExecutor.java:84)
at org.apache.felix.dm.impl.SerialExecutor.access$000(SerialExecutor.java:33)
at org.apache.felix.dm.impl.SerialExecutor$1.run(SerialExecutor.java:50)
at org.apache.felix.dm.impl.SerialExecutor.scheduleNext(SerialExecutor.java:84)
at org.apache.felix.dm.impl.SerialExecutor.execute(SerialExecutor.java:68)
at org.apache.felix.dm.impl.ComponentImpl.calculateStateChanges(ComponentImpl.java:231)
at org.apache.felix.dm.impl.ComponentImpl.start(ComponentImpl.java:399)
at org.apache.felix.dm.DependencyManager.add(DependencyManager.java:169)
at io.github.semr.proflr.impl.Activator.init(Activator.java:14)
at org.apache.felix.dm.DependencyActivatorBase.start(DependencyActivatorBase.java:76)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
at aQute.launcher.Launcher.update(Launcher.java:378)
at aQute.launcher.Launcher.activate(Launcher.java:303)
at aQute.launcher.Launcher.run(Launcher.java:193)
at aQute.launcher.Launcher.main(Launcher.java:89)

我已经搜索了它并得到了 @JsonIgnoreProperties(ignoreUnknown = true) 作为解决方案,但是当我将其插入到我的代码中时,它给出了 enumExpectedError。我认为我没有正确使用注释,如何在我的代码中使用它。

private ObjectMapper mapper = new ObjectMapper();
@Override
public Profile add() {
// read from file, convert it to user class
Profile bean = null;

@JsonIgnoreProperties(ignoreUnknown = true) // I am using it here but show enum expected error

try {

File json = new File("C:\\profile.json");
FileInputStream is = new FileInputStream(json);

bean = mapper.readValue(is,Profile.class);
return bean;

} catch (IOException e) {

e.printStackTrace();
}

return bean;
}

最佳答案

@JsonIgnoreProperties 注释必须用在您要反序列化并且您愿意忽略未知字段的类上:

@JsonIgnoreProperties(ignoreUnknown = true)
public class Profile {
// ...
}

关于java - UnrecognizedPropertyException 无法识别的字段 "resourceType"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27742642/

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