presto-main/src/main/java/io/prestosql/operator/scalar/JsonToRowCast.java/JsonToRowCast/toRow
class JsonToRowCast:    @UsedByGeneratedCode
    public static Block toRow(
            RowType rowType,
            BlockBuilderAppender[] fieldAppenders,
            Optional<Map<String, Integer>> fieldNameToIndex,
            ConnectorSession connectorSession,
            Slice json)
    {
        try (JsonParser jsonParser = createJsonParser(JSON_FACTORY, json)) {
            jsonParser.nextToken();
            if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
                return null;
            }

            if (jsonParser.getCurrentToken() != START_ARRAY && jsonParser.getCurrentToken() != START_OBJECT) {
                throw new JsonCastException(format("Expected a json array or object, but got %s", jsonParser.getText()));
            }

            BlockBuilder rowBlockBuilder = rowType.createBlockBuilder(null, 1);
            parseJsonToSingleRowBlock(
                    jsonParser,
                    (SingleRowBlockWriter) rowBlockBuilder.beginBlockEntry(),
                    fieldAppenders,
                    fieldNameToIndex);
            rowBlockBuilder.closeEntry();

            if (jsonParser.nextToken() != null) {
                throw new JsonCastException(format("Unexpected trailing token: %s", jsonParser.getText()));
            }
            return rowType.getObject(rowBlockBuilder, 0);
        }
        catch (PrestoException | JsonCastException e) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast to %s. %s\n%s", rowType, e.getMessage(), truncateIfNecessaryForErrorMessage(json)), e);
        }
        catch (Exception e) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast to %s.\n%s", rowType, truncateIfNecessaryForErrorMessage(json)), e);
        }
    }