示例#1
0
        internal static ResourceListResult DeserializeResourceListResult(JsonElement element)
        {
            Optional <IReadOnlyList <GenericResourceData> > value = default;
            Optional <string> nextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <GenericResourceData> array = new List <GenericResourceData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(GenericResourceData.DeserializeGenericResource(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("nextLink"))
                {
                    nextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new ResourceListResult(Optional.ToList(value), nextLink.Value));
        }
        public void InvalidDeserializationTest()
        {
            string              json    = "{\"notId\":\"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1\",\"location\":\"eastus\",\"managedBy\":\"ManagedByForResource\",\"name\":\"account1\",\"plan\":{\"name\":\"NameForPlan\",\"publisher\":\"PublisherForPlan\",\"product\":\"ProductForPlan\",\"promotionCode\":\"PromotionCodeForPlan\",\"version\":\"VersionForPlan\"},\"sku\":{\"name\":\"NameForSku\",\"tier\":\"Basic\",\"size\":\"SizeForSku\",\"family\":\"FamilyForSku\",\"capacity\":15464547},\"tags\":{},\"type\":\"Microsoft.ClassicStorage/storageAccounts\"}";
            JsonElement         element = JsonDocument.Parse(json).RootElement;
            GenericResourceData data    = GenericResourceData.DeserializeGenericResource(element);

            Assert.IsNull(data.Id);
            Assert.IsNull(data.Kind);
        }
示例#3
0
 GenericResource IOperationSource <GenericResource> .CreateResult(Response response, CancellationToken cancellationToken)
 {
     using var document = JsonDocument.Parse(response.ContentStream);
     return(new GenericResource(_parentOperation, GenericResourceData.DeserializeGenericResource(document.RootElement)));
 }