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

Error Converting jcas object to json object (Infinite recursion)

我正在尝试使用 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;
    }

但我得到如下无限递归异常

"timestamp": "2020-02-04T10:41:33.342+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Infinite recursion (WhosebugError) (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

任何人都可以提出解决方案吗?

UIMA CAS 对象未设计为可通过 Java 序列化、Jackson 或类似库等标准机制直接序列化。

但 UIMA 框架本身知道如何将 CAS 对象转换为 to/from 多种序列化格式(有些是只写的):

  • UIMA CAS XMI (read/write)
  • UIMA 二进制 CAS(多种变体,read/write)
  • Java 序列化 CAS(通过间接寻址)
  • UIMA CAS JSON(只写)
  • UIMA XCAS (read/write)

有关受支持格式的更多信息,请查看 CasIOUtils