0

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

有人可以提出解决方案吗?

4

1 回答 1

1

UIMA CAS 对象并非旨在通过标准机制(如 Java 序列化、Jackson 或类似库)直接序列化。

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

  • UIMA CAS XMI(读/写)
  • UIMA 二进制 CAS(多种变体,读/写)
  • Java 序列化 CAS(通过间接方式)
  • UIMA CAS JSON(只写)
  • UIMA XCAS(读/写)

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

于 2020-02-05T06:16:30.740 回答