public MetadataResponse deserialize()

in hms-service-api/src/main/java/com/amazonaws/athena/hms/serde/MetadataResponseDeserializer.java [54:122]


  public MetadataResponse deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException
  {
    if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
      throw new IOException("Expected start object.");
    }

    String errorMessage = null;
    String stackTrace = null;
    String apiName = null;
    boolean isSpilled = false;
    String spillPath = null;
    ApiResponse apiResponse = null;
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
      if (jsonParser.getCurrentName() == null) {
        // for error message currentName() could return null at the end
        break;
      }
      switch (jsonParser.getCurrentName()) {
        case ERROR_MESSAGE:
          // move to field value
          jsonParser.nextToken();
          errorMessage = jsonParser.getValueAsString();
          break;
        case STACK_TRACE:
          jsonParser.nextToken();
          stackTrace = jsonParser.getValueAsString();
          break;
        case API_NAME:
          // move to field value
          jsonParser.nextToken();
          apiName = jsonParser.getValueAsString();
          break;
        case IS_SPILLED:
          // move to field value
          jsonParser.nextToken();
          isSpilled = jsonParser.getValueAsBoolean();
          break;
        case SPILL_PATH:
          // move to field value
          jsonParser.nextToken();
          spillPath = jsonParser.getValueAsString();
          break;
        case API_RESPONSE:
          // move to field value
          jsonParser.nextToken();
          // get the request class type
          Class responseClass = apiHelper.getResponseClass(apiName);
          if (responseClass == null) {
            throw new IOException("Cannot find response class for " + apiName);
          }
          if (isSpilled) {
            // Need to read from s3 and convert the String content into the response object
            apiResponse = (ApiResponse) s3Helper.getResponseFromS3As(responseClass, spillPath);
          }
          else {
            // deserialize value based on the response class type
            apiResponse = (ApiResponse) jsonParser.readValueAs(responseClass);
          }
          break;
      }
    }

    if (errorMessage != null) {
      throw new IOException(errorMessage, new Throwable(stackTrace));
    }

    return new MetadataResponse(apiName, isSpilled, spillPath, apiResponse);
  }