com.azure.resourcemanager.servicelinker.models.AzureResource 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.servicelinker.models;
import com.azure.core.annotation.Fluent;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
/**
* The azure resource info when target service type is AzureResource.
*/
@Fluent
public final class AzureResource extends TargetServiceBase {
/*
* The target service type.
*/
private TargetServiceType type = TargetServiceType.AZURE_RESOURCE;
/*
* The Id of azure resource.
*/
private String id;
/*
* The azure resource connection related properties.
*/
private AzureResourcePropertiesBase resourceProperties;
/**
* Creates an instance of AzureResource class.
*/
public AzureResource() {
}
/**
* Get the type property: The target service type.
*
* @return the type value.
*/
@Override
public TargetServiceType type() {
return this.type;
}
/**
* Get the id property: The Id of azure resource.
*
* @return the id value.
*/
public String id() {
return this.id;
}
/**
* Set the id property: The Id of azure resource.
*
* @param id the id value to set.
* @return the AzureResource object itself.
*/
public AzureResource withId(String id) {
this.id = id;
return this;
}
/**
* Get the resourceProperties property: The azure resource connection related properties.
*
* @return the resourceProperties value.
*/
public AzureResourcePropertiesBase resourceProperties() {
return this.resourceProperties;
}
/**
* Set the resourceProperties property: The azure resource connection related properties.
*
* @param resourceProperties the resourceProperties value to set.
* @return the AzureResource object itself.
*/
public AzureResource withResourceProperties(AzureResourcePropertiesBase resourceProperties) {
this.resourceProperties = resourceProperties;
return this;
}
/**
* Validates the instance.
*
* @throws IllegalArgumentException thrown if the instance is not valid.
*/
@Override
public void validate() {
if (resourceProperties() != null) {
resourceProperties().validate();
}
}
/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString());
jsonWriter.writeStringField("id", this.id);
jsonWriter.writeJsonField("resourceProperties", this.resourceProperties);
return jsonWriter.writeEndObject();
}
/**
* Reads an instance of AzureResource from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of AzureResource if the JsonReader was pointing to an instance of it, or null if it was
* pointing to JSON null.
* @throws IOException If an error occurs while reading the AzureResource.
*/
public static AzureResource fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
AzureResource deserializedAzureResource = new AzureResource();
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("type".equals(fieldName)) {
deserializedAzureResource.type = TargetServiceType.fromString(reader.getString());
} else if ("id".equals(fieldName)) {
deserializedAzureResource.id = reader.getString();
} else if ("resourceProperties".equals(fieldName)) {
deserializedAzureResource.resourceProperties = AzureResourcePropertiesBase.fromJson(reader);
} else {
reader.skipChildren();
}
}
return deserializedAzureResource;
});
}
}