{"usage":{"text_characters":22,"features":1,"text_units":1},"entities":[{"count":1,"text":"pisos","disambiguation":{"subtype":["NONE"]},"type":"Producto"},{"count":1,"text":"No hay","disambiguation":{"subtype":["NONE"]},"type":"Quiebre_Stock"},{"count":1,"text":"madera","disambiguation":{"subtype":["NONE"]},"type":"Producto"}],"language":"es"}
parsedJsonObj = mapper.readValue(result, NLUEntitiesRelations.class);
nluentitiesrelations.class
如下所示
public class NLUEntitiesRelations {
private UsageNLU usage;
private List<EntityNLU> entities;
private String language;
//getter and setter
}
public class UsageNLU {
private int text_characters;
private int features;
private int text_units;
//getersand setter
}
public class EntityNLU {
private int count;
private String text;
private DisambiguationNLU disambiguation;
private String type;
//getter and setter
}
public class DisambiguationNLU {
private List<String> subtype;
//getter and setter
}
但是在执行它时,我遇到了以下错误,当它是JSON中的JSON时,我很小心地创建了一个新类,就像在usagenlu中一样
Error: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: { "usage": { "text_units": 1, "text_characters": 22, "features": 1 }, "language": "es", "entities": [ { "type": "Producto", "text": "pisos", "disambiguation": { "subtype": [ "NONE" ] }, "count": 1 }, { "type": "Quiebre_Stock", "text": "no hay", "disambiguation": { "subtype": [ "NONE" ] }, "count": 1 }, { "type": "Producto", "text": "madera", "disambiguation": { "subtype": [ "NONE" ] }, "count": 1 } ] } ; line: 2, column: 12] (through reference chain: cl.sodimac.watson.alchemy.json.NLUEntitiesRelations["usage"])
在JSON的实体部分中有如下内容:
"disambiguation": {
"subtype": [
"NONE"
]
}
这意味着Java类存在两个问题,使它们与JSON内容不兼容:
类entitynlu
私有消歧nlu消歧;
(没有列表<>
)私有列表
消歧;
类disambiguationnlu
私有列表
子类型;
(小写t
)私有列表
子类型;
例外情况: 套接字处理程序 我相信当JSON被解析为WorkstationRequest对象时会出现异常,原因是下面的项。这是套接字处理程序: 我不知道如何开始调试它。堆栈跟踪从未触及我的应用程序。我正在使用部署我的.jar,并使用执行它
我第一次遇到ObjectMapper与string.class一起使用,我尝试将json作为string提供,得到了JSONMappingException。你能帮我理解一下为什么吗? 答复: 线程“Main”Com.FasterXml.Jackson.DataBind.JsonMappingException异常:无法反序列化位于[Source:{“Response”:“Success”}处的S
我想用Spring Boot编写一个小而简单的REST服务。下面是REST服务代码: 我发送的JSON对象如下: 警告964---[XNIO-2 task-7].w.s.m.s.DefaultHandlerExceptionResolver:无法读取HTTP消息:org.SpringFramework.HTTP.Converter.HttpMessageNotReadableException:无
下面有一个JSON,我试图使用Jackson将其解析为POJO 我的响应POJO片段如下 以及他们的吸气手和二传手 当我得到“org.codehaus.jackson.map.jsonMappingException:Can not deserialize instance of java.util.list out of START_OBJECT token”时,我的声明是否错误? 解析逻辑如下
我编写了一个微服务来对API进行HTTP调用。代码如下所示。 当我使用构建它时,它运行得非常完美。然而,当我将其作为SpringBoot应用程序运行时,我会得到以下错误:
如果您看到我的实体类,我在teacher.java中有一组枚举。 当我试着发布这个时,我会出错 我已经尝试了几乎所有的解决方案,比如,但没有成功。