本文介绍了Xpages SBT< xe:restJsonData> & java.util.ArrayList与com.ibm.commons.util.io.json.JsonJavaObject不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在XPages中的SBT中使用Endpoint功能,并使用不同的Rest服务(与示例中的服务不同).经过几次调整(Serdar!),身份验证仍然有效,但我想模仿StackOverflow示例,并通过<xe:restJsonData>使用响应并重复控制.

I'm trying to use the Endpoint functionality in SBT within XPages with a different rest service (to those in the examples).The authentication is working after a few tweaks (thanks Serdar!) but I wanted to mimic the StackOverflow example and use the response via a <xe:restJsonData> and repeat control.

使用SO示例作为起点,如果我更改参数以匹配我的服务,则会出现此错误...

Using the SO example as I starting point if I change the params to match my service I get this error...

Error while reading the JSON streamjava.util.ArrayList incompatible with com.ibm.commons.util.io.json.JsonJavaObject

Error while reading the JSON streamjava.util.ArrayList incompatible with com.ibm.commons.util.io.json.JsonJavaObject

我猜想这与splitpath有关,因为生成的json没有这样的公共父级.看起来有点像这样(编辑)...

I'm guessing it's something to do with the splitpath as the resulting json doesn't have a common parent as such. Looks a bit like this (edited)...

[ { "user_id": 1688810, "space_id": null, "type": "user", "title": [ "Workflow Architect" ], "external_id": null, "last_seen_on": "2014-07-21 06:42:03", "name": "XXX XXX" }, { "user_id": 1998697, "name": "YYY YYY", "rights": [ "view" ], "external_id": null, "space_id": null, "title": [ "Owner" ], "org_id": null, "country": "United States", "type": "user", "last_seen_on": "2014-07-20 16:52:03", "location": [ "Amarillo" ] }]我尝试了空白或"/"的拆分路径,但得到相同的错误.我知道数据会随着输入的计算值而返回@Endpoint("podio").xhrGet("/contact/").getData();显示正常(原始)

[ { "user_id": 1688810, "space_id": null, "type": "user", "title": [ "Workflow Architect" ], "external_id": null, "last_seen_on": "2014-07-21 06:42:03", "name": "XXX XXX" }, { "user_id": 1998697, "name": "YYY YYY", "rights": [ "view" ], "external_id": null, "space_id": null, "title": [ "Owner" ], "org_id": null, "country": "United States", "type": "user", "last_seen_on": "2014-07-20 16:52:03", "location": [ "Amarillo" ] }]I've tried a split path of blank or "/" but get the same error. I know the data is coming back as putting in a computed value of@Endpoint("podio").xhrGet("/contact/").getData();shows it ok (raw)

有什么想法可以将结果拆分为工作,或者由于json很复杂,从根本上讲该对象根本无法实现吗?谢谢!

Any ideas how I can split this result to work or is it fundamentally not possible with that object as the json is complex?Thanks!

完整堆栈跟踪...

com.ibm.xsp.FacesExceptionEx: Error while reading the JSON stream
at com.ibm.xsp.extlib.sbt.generic.GenericRestJsonDataSource$JsonAccessor.loadBlock(GenericRestJsonDataSource.java:137)
at com.ibm.xsp.extlib.model.DataBlockAccessor.findBlockByIndex(DataBlockAccessor.java:344)
at com.ibm.xsp.extlib.model.DataBlockAccessor.prefetchData(DataBlockAccessor.java:292)
at com.ibm.xsp.extlib.model.DataAccessorModel.getRowCount(DataAccessorModel.java:93)
at com.ibm.xsp.model.TabularDataModel.isRowAvailable(TabularDataModel.java:96)
at com.ibm.xsp.extlib.model.DataAccessorModel.isRowAvailable(DataAccessorModel.java:69)
at com.ibm.xsp.component.UIDataIterator.isRowAvailable(UIDataIterator.java:523)
at com.ibm.xsp.component.UIDataIterator.pushVars(UIDataIterator.java:504)
at com.ibm.xsp.component.UIDataIterator.setRowIndex(UIDataIterator.java:469)
at com.ibm.xsp.renderkit.html_extended.IteratorRenderer.encodeRows(IteratorRenderer.java:62)
at com.ibm.xsp.renderkit.html_extended.IteratorRenderer.encodeChildren(IteratorRenderer.java:55)
at com.ibm.xsp.renderkit.ReadOnlyAdapterRenderer.encodeChildren(ReadOnlyAdapterRenderer.java:162)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:979)
at com.ibm.xsp.component.UIDataIterator.encodeChildren(UIDataIterator.java:725)
at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:844)
at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)
at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)
at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)
at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)
at com.ibm.xsp.component.UIViewRootEx._renderView(UIViewRootEx.java:1317)
at com.ibm.xsp.component.UIViewRootEx.renderView(UIViewRootEx.java:1255)
at com.ibm.xsp.application.ViewHandlerExImpl.doRender(ViewHandlerExImpl.java:651)
at com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:321)
at com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:336)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:103)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:120)
at com.ibm.xsp.controller.FacesControllerImpl.render(FacesControllerImpl.java:270)
at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:261)
at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1315)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:853)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1299)
at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)
at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:350)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:306)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
Caused by: java.lang.ClassCastException: java.util.ArrayList incompatible with com.ibm.commons.util.io.json.JsonJavaObject
at com.ibm.xsp.extlib.sbt.generic.GenericRestJsonDataSource$JsonAccessor.loadBlock(GenericRestJsonDataSource.java:121)
... 43 more'

推荐答案

我之前遇到过同样的问题.这是GenericRestJsonDataSource的功能.如果远程服务提供的是数组而不是对象,则来自客户端服务的数据将返回JsonJavaObjectArrayList.

I have bumped the same problem before. That's an incapability of GenericRestJsonDataSource. If the remote service provides an array, instead of an object, the data from the client service returns an ArrayList of JsonJavaObject's.

但是,它希望包含JsonJavaObjectArrayListJsonJavaObject.

However it expects an JsonJavaObject that contains an ArrayList of JsonJavaObject's.

这就是为什么在前面的BaseCamp示例中(在链接的问题上)我设计了一个额外的Java Bean,该Java Bean提取数据并维护其自己的List结构.那对缓存也有很大帮助.

That's why in the previous example of BaseCamp (at the linked question) I have designed an additional Java bean that pulls the data and maintains its own List structures. That also helped me a lot on caching.

您的数据应采用以下格式:

Your data should be in a format like:

{
  items: [
     {
       prop: value, ....
     },
     {
       prop: value, ....
     }
  ]
}

就像在SO示例中一样.在这种情况下,splitPath应该为items.

Just like in the SO example. In this case splitPath should be items.

实际上,这是在班上的一个简单修复.应该修改GenericRestJsonDataSource中的访问器类,以检查返回的项目是否为ArrayList.但是,在当时,设计自己的Service Bean似乎是一种更方便的方法.

That's an easy fix within the class in fact. The accessor class in the GenericRestJsonDataSource should be modified to check if the returning item is an ArrayList. However at the time, it seemed like a more convenient method to design my own Service bean.

这篇关于Xpages SBT&lt; xe:restJsonData&gt; &amp; java.util.ArrayList与com.ibm.commons.util.io.json.JsonJavaObject不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 00:59