简体   繁体   English

将 jcas 对象转换为 json 对象时出错(无限递归)

[英]Error Converting jcas object to json object (Infinite recursion)

I am trying to convert a JCas object (org.apache.uima.jcas.JCas) to json string using jackson ObjectMapper as following.我正在尝试使用 jackson ObjectMapper 将 JCas 对象(org.apache.uima.jcas.JCas)转换为 json 字符串,如下所示。

public Map<String, List<CuiResponse>> process(final String text) throws ServletException {
        JCas jcas = null;
        Map<String, List<CuiResponse>> resultMap = null;
        if (text != null) {
            try {
                jcas = _pool.getJCas(-1);
                jcas.setDocumentText(text);
                _engine.process(jcas);

                ObjectMapper mapper = new ObjectMapper();
                String jsonString = mapper.writeValueAsString(jcas);


                resultMap = formatResults(jcas);
                _pool.releaseJCas(jcas);
            } catch (Exception e) {
                throw new ServletException(e);
            }
        }
        return resultMap;
    }

But I am getting Infinite recursion exception as below但我得到如下无限递归异常

"timestamp": "2020-02-04T10:41:33.342+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Infinite recursion (StackOverflowError) (through reference chain: org.apache.uima.cas.impl.TypeSystemImpl[\"features\"]->org.apache.uima.cas.impl.FeatureImpl[\"range\"]->org.apache.uima.cas.impl.TypeImpl[\"typeSystem\"]->org.apache.uima.cas.impl.TypeSystemImpl[\"features\"]->org.apache.uima.cas.impl.FeatureImpl[\"range\"]->org.apache.uima.cas.impl.TypeImpl[\"typeSystem\"]->org.apache.uima.cas.impl.TypeSystemImpl[\"features\"]->org.apache.uima.cas.impl.FeatureImpl[\"range\"]->org.apache.uima.cas.impl.TypeImpl[\"typeSystem\"]->org.apache.uima.cas.impl.TypeSystemImpl[\"features\"]->org.apache.uima.cas.impl.FeatureImpl[\"range\"]->org.apache.uima.cas.impl.TypeImpl[\"typeSystem\"]->org.apache.uima.cas.impl.TypeSystemImpl[\"features\"]->org.apache.uima.cas.impl.FeatureImpl[\"range\"]->org.apache.uima.cas.impl.TypeImpl[\"typeSystem\"]->org.apache.uima.cas.impl.TypeSystemImpl[\"features\"]->org.apache.uima.cas.impl.FeatureImpl[\"range\"]->org.apache.uima.cas.impl.TypeImpl[\"typeSystem\"]->org

Can anybody suggest a solution?有人可以提出解决方案吗?

UIMA CAS objects are not designed to be directly serializable by standard mechanisms such as Java Serialization, Jackson or similar libraries. UIMA CAS 对象并非设计为可通过标准机制直接序列化,例如 Java 序列化、Jackson 或类似库。

But the UIMA framework itself knows how to convert a CAS object to/from a number of serialization formats (some write-only):但是 UIMA 框架本身知道如何将 CAS 对象转换为多种序列化格式(一些只写格式):

  • UIMA CAS XMI (read/write) UIMA CAS XMI(读/写)
  • UIMA Binary CAS (several variations, read/write) UIMA 二进制 CAS(多种变体,读/写)
  • Java Serialized CAS (through an indirection) Java 序列化 CAS(通过间接方式)
  • UIMA CAS JSON (write-only) UIMA CAS JSON(只写)
  • UIMA XCAS (read/write) UIMA XCAS(读/写)

For more information on supported formats, check out CasIOUtils .有关支持的格式的更多信息,请查看CasIOUtils

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM