例外情况:
Receiving an event {id=2, socket=0c317829-69bf-43d6-b598-7c0c550635bb, type=getDashboard, data={workstationUuid=ddec1caa-a97f-4922-833f-632da07ffc11}, reply=true}
Firing getDashboard event to Socket#0c317829-69bf-43d6-b598-7c0c550635bb
Failed invoking AtmosphereFramework.doCometSupport()
java.lang.IllegalArgumentException: Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: N/A; line: -1, column: -1]
at org.codehaus.jackson.map.ObjectMapper._convert(ObjectMapper.java:2502)
at org.codehaus.jackson.map.ObjectMapper.convertValue(ObjectMapper.java:2468)
at com.github.flowersinthesand.portal.support.DefaultDispatcher$DefaultHandler$DataParam.resolve(DefaultDispatcher.java:270)
at com.github.flowersinthesand.portal.support.DefaultDispatcher$DefaultHandler.handle(DefaultDispatcher.java:204)
at com.github.flowersinthesand.portal.support.DefaultDispatcher.fire(DefaultDispatcher.java:107)
at com.github.flowersinthesand.portal.support.AbstractSocketFactory.fire(AbstractSocketFactory.java:73)
at com.github.flowersinthesand.portal.atmosphere.AtmosphereSocketFactory.onRequest(AtmosphereSocketFactory.java:75)
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:256)
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:166)
at org.atmosphere.container.Grizzly2WebSocketSupport.service(Grizzly2WebSocketSupport.java:75)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1342)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:219)
at org.atmosphere.websocket.DefaultWebSocketProcessor$2.run(DefaultWebSocketProcessor.java:183)
at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:178)
at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:167)
at org.atmosphere.container.Grizzly2WebSocketSupport$Grizzly2WebSocketApplication.onMessage(Grizzly2WebSocketSupport.java:171)
at org.glassfish.grizzly.websockets.DefaultWebSocket.onMessage(DefaultWebSocket.java:164)
at org.glassfish.grizzly.websockets.frametypes.TextFrameType.respond(TextFrameType.java:70)
at org.glassfish.grizzly.websockets.DataFrame.respond(DataFrame.java:104)
at org.glassfish.grizzly.websockets.WebSocketFilter.handleRead(WebSocketFilter.java:221)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:78)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:770)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:551)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:531)
at java.lang.Thread.run(Thread.java:781)
Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: N/A; line: -1, column: -1]
at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
at org.codehaus.jackson.map.deser.std.StringDeserializer.deserialize(StringDeserializer.java:44)
at org.codehaus.jackson.map.deser.std.StringDeserializer.deserialize(StringDeserializer.java:13)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
at org.codehaus.jackson.map.ObjectMapper._convert(ObjectMapper.java:2498)
... 34 more
java.lang.IllegalArgumentException: Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: N/A; line: -1, column: -1] Status 500 Message Server Error
套接字处理程序
我相信当JSON被解析为WorkstationRequest对象时会出现异常,原因是下面的项。这是套接字处理程序:
@On
@Reply
@JsonView({Views.WorkstationView.class})
public WorkstationDashboard getDashboard(@Data WorkstationRequest request) {
return new WorkstationDashboard(request.getWorkstation());
}
public class WorkstationRequest {
/* Class to instantiate if this workstation does not already exist */
private Class<? extends Workstation> workstationClass;
private WorkflowProcess workflowProcess;
private PhysicalWorkstation workstation;
WorkstationService workstationService;
/**
* @param workstationClass Required so when jackson maps the UUID we can auto fetch the class
*/
public WorkstationRequest(Class<? extends Workstation> workstationClass) {
this.workstationClass = workstationClass;
workstationService = (WorkstationService) ApplicationContextProvider.getApplicationContext().getBean("workstationService");
}
/* Set the workstation based on UUID. Will register the workstation if it's new */
@JsonProperty("workstationUuid")
public void setWorkstation(String workstationUUID) {
workstation = (PhysicalWorkstation)WorkstationService.getWorkstation(workstationUUID);
//setup new workstation
if (workstation == null) {
WorkstationEntity workstationEntity = workstationService.findByUUID(workstationUUID);
workstation = (PhysicalWorkstation)Workstation.factory(workstationEntity, workstationClass);
//register with queue
WorkflowProcessService.getWorkflowProcess(workstation).registerWorkstation(workstation);
}
}
public PhysicalWorkstation getWorkstation() {
return workstation;
}
}
{"id":2,"socket":"0c317829-69bf-43d6-b598-7c0c550635bb","type":"getDashboard","data":{"workstationUuid":"ddec1caa-a97f-4922-833f-632da07ffc11"},"reply":true}
public class WorkstationDashboard {
private HashMap<String, Object> queue = new HashMap<String, Object>();
private LinkedBlockingDeque<JobSetEntity> currentWork;
public WorkstationDashboard() {
queue.put("size", 0);
}
public WorkstationDashboard(Workstation workstation) {
fromWorkstation(workstation);
}
/* Populate dashboard data from a workstation */
public void fromWorkstation(Workstation workstation) {
WorkflowProcess workflowProcess = WorkflowProcessService.getWorkflowProcess(workstation);
setCurrentWork(workstation.getCurrentWork());
setQueueSize(workflowProcess.getQueue().size());
}
public void setQueueSize(Integer queueSize) {
queue.put("size", queueSize);
}
public HashMap<String, Object> getQueue() {
return queue;
}
public LinkedBlockingDeque<JobSetEntity> getCurrentWork() {
return currentWork;
}
public void setCurrentWork(LinkedBlockingDeque<JobSetEntity> currentWork) {
this.currentWork = currentWork;
}
}
我不知道如何开始调试它。堆栈跟踪从未触及我的应用程序。我正在使用maven->package
部署我的.jar,并使用java-jar/path-to-jar.jar
执行它
您正在映射这个JSON
{
"id": 2,
"socket": "0c317829-69bf-43d6-b598-7c0c550635bb",
"type": "getDashboard",
"data": {
"workstationUuid": "ddec1caa-a97f-4922-833f-632da07ffc11"
},
"reply": true
}
它包含一个名为data
的元素,该元素的值是一个JSON对象。您正在尝试将名为workstationuuid
的元素从该JSON对象反序列化到这个setter中。
@JsonProperty("workstationUuid")
public void setWorkstation(String workstationUUID) {
这不会直接起作用,因为Jackson看到的是一个JSON_OBJECT,而不是一个字符串。
public class Data { // the name doesn't matter
@JsonProperty("workstationUuid")
private String workstationUuid;
// getter and setter
}
@JsonProperty("data")
public void setWorkstation(Data data) {
// use getter to retrieve it
我编写了一个微服务来对API进行HTTP调用。代码如下所示。 当我使用构建它时,它运行得非常完美。然而,当我将其作为SpringBoot应用程序运行时,我会得到以下错误:
我尝试声明为String或List,但没有成功。知道吗? }
我第一次遇到ObjectMapper与string.class一起使用,我尝试将json作为string提供,得到了JSONMappingException。你能帮我理解一下为什么吗? 答复: 线程“Main”Com.FasterXml.Jackson.DataBind.JsonMappingException异常:无法反序列化位于[Source:{“Response”:“Success”}处的S
我正在尝试发布一个自定义对象的。请求体中的JSON如下所示: 处理请求的服务器端代码: 实体: 但会引发异常:
在执行从serviceA到serviceB的请求时, serviceA中的测试请求是
下面是POJO类: 主要功能如下: