public QueryResult()

in provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/configs/QueryResult.java [88:149]


    public QueryResult(String type, String body, String continuationToken)
    {
        /* SRS_QUERY_RESULT_21_001: [The constructor shall throw IllegalArgumentException if the provided type is null, empty, or not parsed to QueryResultType.] */
        QueryResultType queryResultType = QueryResultType.fromString(type);
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().disableHtmlEscaping().create();

        /* SRS_QUERY_RESULT_21_002: [The constructor shall throw IllegalArgumentException if the provided body is null or empty and the type is not `unknown`.] */
        if ((queryResultType != QueryResultType.UNKNOWN) && (body == null || body.isEmpty()))
        {
            throw new IllegalArgumentException("body cannot be null or empty");
        }

        /* SRS_QUERY_RESULT_21_003: [The constructor shall throw JsonSyntaxException if the JSON is invalid.] */
        switch(queryResultType)
        {
            case ENROLLMENT:
                /* SRS_QUERY_RESULT_21_004: [If the type is `enrollment`, the constructor shall parse the body as IndividualEnrollment[].] */
                this.items = gson.fromJson(body, IndividualEnrollment[].class);
                break;
            case ENROLLMENT_GROUP:
                /* SRS_QUERY_RESULT_21_005: [If the type is `enrollmentGroup`, the constructor shall parse the body as EnrollmentGroup[].] */
                this.items = gson.fromJson(body, EnrollmentGroup[].class);
                break;
            case DEVICE_REGISTRATION:
                /* SRS_QUERY_RESULT_21_006: [If the type is `deviceRegistration`, the constructor shall parse the body as DeviceRegistrationState[].] */
                this.items = gson.fromJson(body, DeviceRegistrationState[].class);
                break;
            default:
                if (body == null)
                {
                    /* SRS_QUERY_RESULT_21_007: [If the type is `unknown`, and the body is null, the constructor shall set `items` as null.] */
                    this.items = null;
                }
                else
                {
                    try
                    {
                        /* SRS_QUERY_RESULT_21_008: [If the type is `unknown`, the constructor shall try to parse the body as JsonObject[].] */
                        this.items = gson.fromJson(body, JsonObject[].class);
                    }
                    catch (JsonSyntaxException e1)
                    {
                        try
                        {
                            /* SRS_QUERY_RESULT_21_009: [If the type is `unknown`, and the constructor failed to parse the body as JsonObject[], it shall try to parse the body as JsonPrimitive[].] */
                            this.items = gson.fromJson(body, JsonPrimitive[].class);
                        }
                        catch (JsonSyntaxException e2)
                        {
                            /* SRS_QUERY_RESULT_21_010: [If the type is `unknown`, and the constructor failed to parse the body as JsonObject[] and JsonPrimitive[], it shall return the body as a single string in the items.] */
                            this.items = new String[1];
                            this.items[0] = body;
                        }
                    }
                }
                break;
        }

        /* SRS_QUERY_RESULT_21_011: [The constructor shall store the provided parameters `type` and `continuationToken`.] */
        this.type = queryResultType;
        this.continuationToken = continuationToken;
    }