All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.resourcemanager.policyinsights.models.PendingField Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.policyinsights.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;

/**
 * A field that should be evaluated against Azure Policy to determine restrictions.
 */
@Fluent
public final class PendingField implements JsonSerializable {
    /*
     * The name of the field. This can be a top-level property like 'name' or 'type' or an Azure Policy field alias.
     */
    private String field;

    /*
     * The list of potential values for the field that should be evaluated against Azure Policy.
     */
    private List values;

    /**
     * Creates an instance of PendingField class.
     */
    public PendingField() {
    }

    /**
     * Get the field property: The name of the field. This can be a top-level property like 'name' or 'type' or an Azure
     * Policy field alias.
     * 
     * @return the field value.
     */
    public String field() {
        return this.field;
    }

    /**
     * Set the field property: The name of the field. This can be a top-level property like 'name' or 'type' or an Azure
     * Policy field alias.
     * 
     * @param field the field value to set.
     * @return the PendingField object itself.
     */
    public PendingField withField(String field) {
        this.field = field;
        return this;
    }

    /**
     * Get the values property: The list of potential values for the field that should be evaluated against Azure
     * Policy.
     * 
     * @return the values value.
     */
    public List values() {
        return this.values;
    }

    /**
     * Set the values property: The list of potential values for the field that should be evaluated against Azure
     * Policy.
     * 
     * @param values the values value to set.
     * @return the PendingField object itself.
     */
    public PendingField withValues(List values) {
        this.values = values;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (field() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException("Missing required property field in model PendingField"));
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(PendingField.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("field", this.field);
        jsonWriter.writeArrayField("values", this.values, (writer, element) -> writer.writeString(element));
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of PendingField from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of PendingField if the JsonReader was pointing to an instance of it, or null if it was
     * pointing to JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the PendingField.
     */
    public static PendingField fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            PendingField deserializedPendingField = new PendingField();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("field".equals(fieldName)) {
                    deserializedPendingField.field = reader.getString();
                } else if ("values".equals(fieldName)) {
                    List values = reader.readArray(reader1 -> reader1.getString());
                    deserializedPendingField.values = values;
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedPendingField;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy