public CAS deserialize()

in src/main/java/org/apache/uima/json/jsoncas2/ser/CasDeserializer.java [56:125]


  public CAS deserialize(JsonParser aParser, DeserializationContext aCtxt)
          throws IOException, JsonProcessingException {

    FeatureStructureIdToViewIndex.set(aCtxt, new FeatureStructureIdToViewIndex());
    FeatureStructureToIdIndex.set(aCtxt, new FeatureStructureToIdIndex());

    boolean isFirst = true;
    CAS cas = null;
    TypeSystemDescription types = null;

    while (aParser.currentToken() != null) {
      if (isFirst) {
        isFirst = false;
        switch (aParser.currentTokenId()) {
          // case ID_STRING:
          // readDocumentText(aCas, parser.getValueAsString());
          // return;
          // case ID_START_ARRAY:
          // jfses = readFeatureStructuresAsArray(parser);
          // return;
          case ID_START_OBJECT:
            // In this case, we continue in the main loop and process the type system and
            // feature structures if we find them.
            aParser.nextFieldName();
            break;
          default:
            throw new IOException("JSON must start with an object, array or string value, but was ["
                    + aParser.currentTokenId() + "]");
        }
      }

      if (aParser.currentTokenId() == ID_END_ARRAY || aParser.currentTokenId() == ID_END_OBJECT) {
        break;
      }

      // If we get here, we are operating on an object-type representation of the full CAS
      switch (aParser.getCurrentName()) {
        case HEADER_FIELD: {
          aParser.nextValue();
          Header header = aCtxt.readValue(aParser, Header.class);
          OffsetConversionMode.set(aCtxt, header.getOffsetEncoding());
          aParser.nextToken();
          break;
        }
        case TYPES_FIELD:
          aParser.nextValue();
          types = aCtxt.readValue(aParser, TypeSystemDescription.class);
          aParser.nextValue();
          cas = createCasOrGetFromContext(aCtxt, types);
          break;
        case VIEWS_FIELD:
          aCtxt.readValue(aParser, Views.class);
          break;
        case FEATURE_STRUCTURES_FIELD:
          aCtxt.readValue(aParser, FeatureStructures.class);
          break;
      }
    }

    // Index FS in the respective views
    FeatureStructureIdToViewIndex fsIdToViewIndex = FeatureStructureIdToViewIndex.get(aCtxt);
    for (Entry<Integer, FeatureStructure> fsEntry : FeatureStructureToIdIndex.get(aCtxt)
            .getAllFeatureStructures()) {
      for (String viewName : fsIdToViewIndex.getViewsContainingFs(fsEntry.getKey())) {
        cas.getView(viewName).addFsToIndexes(fsEntry.getValue());
      }
    }

    return cas;
  }