diff --git a/.chronus/changes/copilot-use-utf8jsonreader-collectionresult-2026-03-05.md b/.chronus/changes/copilot-use-utf8jsonreader-collectionresult-2026-03-05.md new file mode 100644 index 00000000000..2df223e1642 --- /dev/null +++ b/.chronus/changes/copilot-use-utf8jsonreader-collectionresult-2026-03-05.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@typespec/http-client-csharp" +--- + +Use `Utf8JsonReader` for untyped `CollectionResult` to efficiently read the continuation token or next link from the response body without fully deserializing the envelope model type. Nested property paths are supported. diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/CollectionResultDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/CollectionResultDefinition.cs index d704c3eec74..fd7866cf864 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/CollectionResultDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/CollectionResultDefinition.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.TypeSpec.Generator.ClientModel.Snippets; using Microsoft.TypeSpec.Generator.ClientModel.Utilities; @@ -337,8 +338,6 @@ private MethodBodyStatement[] BuildGetContinuationToken() switch (NextPageLocation) { case InputResponseLocation.Body: - var resultExpression = GetPropertyExpression(nextPagePropertySegments!, PageParameter.AsVariable()); - var ifElseStatement = nextPageType.Equals(typeof(Uri)) ? new IfElseStatement(new IfStatement(nextPageVariable.NotEqual(Null)) { @@ -357,6 +356,16 @@ private MethodBodyStatement[] BuildGetContinuationToken() }, Return(Null)); + // For the untyped CollectionResult (no item model type), use Utf8JsonReader to read only + // the specific properties needed from the response, avoiding full model deserialization. + if (ItemModelType == null) + { + var contentExpression = PageParameter.ToApi().GetRawResponse().Content(); + var readStatements = BuildReadNextPageWithUtf8JsonReader(nextPageVariable, contentExpression, nextPagePropertySegments!, declareVariable: true); + return [.. readStatements, ifElseStatement]; + } + + var resultExpression = GetPropertyExpression(nextPagePropertySegments!, PageParameter.AsVariable()); return [ Declare(nextPageVariable, resultExpression), @@ -380,6 +389,127 @@ private MethodBodyStatement[] BuildGetContinuationToken() } } + /// + /// Builds the statements to read the next page value from a JSON response using Utf8JsonReader, + /// navigating through the given property segments path. This avoids deserializing the entire + /// response into the model type when only specific properties are needed. + /// + /// The variable to assign the next page value to. + /// The expression to get the response content from. + /// The JSON property path segments to navigate. + /// + /// When true, the first statement declares the variable with a null initializer. + /// When false, the first statement is an assignment to null (variable already declared). + /// + private MethodBodyStatement[] BuildReadNextPageWithUtf8JsonReader( + VariableExpression nextPageVar, + ValueExpression contentExpression, + IReadOnlyList segments, + bool declareVariable = false) + { + var dataVar = new VariableExpression(typeof(BinaryData), "data"); + var readerVar = new VariableExpression(typeof(Utf8JsonReader), "reader"); + + MethodBodyStatement initStatement = declareVariable + ? Declare(nextPageVar, Null) + : nextPageVar.Assign(Null).Terminate(); + + return + [ + // Initialize next page variable to null + initStatement, + // Declare data from the response content + Declare(dataVar, contentExpression), + // Declare reader from the data span + Declare(readerVar, New.Instance(typeof(Utf8JsonReader), ReadOnlyMemorySnippets.Span(dataVar.As().ToMemory()))), + // Read past the root StartObject token + readerVar.Read().Terminate(), + // Navigate the JSON path and assign the next page value + BuildReaderLoopForSegments(readerVar, nextPageVar, segments, 0) + ]; + } + + /// + /// Recursively builds a while loop that navigates a JSON reader through the given property segments + /// and assigns the found value to the target variable. + /// + private WhileStatement BuildReaderLoopForSegments( + VariableExpression reader, + VariableExpression targetVar, + IReadOnlyList segments, + int segmentIndex) + { + var propertyName = segments[segmentIndex]; + bool isLastSegment = segmentIndex == segments.Count - 1; + + // Condition: reader.TokenType == PropertyName && reader.ValueTextEquals(propertyName) + var isPropertyMatch = reader.TokenType().Equal(JsonTokenTypeSnippets.PropertyName) + .And(reader.ValueTextEquals(propertyName)); + + var loop = new WhileStatement(reader.Read()); + + // Build the "found property" handler + var foundPropertyStatement = new IfStatement(isPropertyMatch); + if (isLastSegment) + { + // Read the value and assign to target + foreach (var stmt in BuildTerminalPropertyReadStatements(reader, targetVar)) + foundPropertyStatement.Add(stmt); + } + else + { + // Navigate into the nested object + var innerLoop = BuildReaderLoopForSegments(reader, targetVar, segments, segmentIndex + 1); + foundPropertyStatement.Add(reader.Read().Terminate()); + foundPropertyStatement.Add(new IfStatement(reader.TokenType().Equal(JsonTokenTypeSnippets.StartObject)) { innerLoop }); + foundPropertyStatement.Add(Break); + } + + loop.Add(foundPropertyStatement); + + // Skip nested objects/arrays that appear as property values to avoid false property name matches + loop.Add(new IfStatement( + reader.TokenType().Equal(JsonTokenTypeSnippets.StartObject) + .Or(reader.TokenType().Equal(JsonTokenTypeSnippets.StartArray))) + { + reader.Skip().Terminate() + }); + + return loop; + } + + /// + /// Builds the statements to read the terminal property value from the reader and assign it to the target variable. + /// + private static MethodBodyStatement[] BuildTerminalPropertyReadStatements( + VariableExpression reader, + VariableExpression targetVar) + { + if (targetVar.Type.Equals(typeof(Uri))) + { + // Read the string value and convert to Uri if non-empty + var strVar = new VariableExpression(typeof(string), "nextPageStr"); + return + [ + reader.Read().Terminate(), + Declare(strVar, reader.GetString()), + new IfStatement(Not(Static().Invoke(nameof(string.IsNullOrEmpty), strVar))) + { + targetVar.Assign(New.Instance(strVar, FrameworkEnumValue(UriKind.RelativeOrAbsolute))).Terminate() + }, + Break + ]; + } + + // Read the string value directly + return + [ + reader.Read().Terminate(), + targetVar.Assign(reader.GetString()).Terminate(), + Break + ]; + } + private MethodBodyStatement[] BuildGetRawPagesForNextLink() { var nextPageVariable = new VariableExpression(typeof(Uri), "nextPageUri"); @@ -482,6 +612,21 @@ protected MethodBodyStatement[] AssignAndCheckNextPageVariable(ClientResponseApi switch (NextPageLocation) { case InputResponseLocation.Body: + // For the untyped CollectionResult (no item model type), use Utf8JsonReader to read only + // the specific properties needed from the response, avoiding full model deserialization. + if (ItemModelType == null) + { + var contentExpression = result.GetRawResponse().Content(); + var readStatements = BuildReadNextPageWithUtf8JsonReader(nextPage, contentExpression, NextPagePropertySegments); + + IfStatement nullCheckCondition = nextPage.Type.Equals(typeof(Uri)) + ? new IfStatement(nextPage.Equal(Null)) + : new IfStatement(Static().Invoke(nameof(string.IsNullOrEmpty), nextPage)); + nullCheckCondition.Add(YieldBreak()); + + return [.. readStatements, nullCheckCondition]; + } + var resultExpression = BuildGetPropertyExpression(NextPagePropertySegments, responseModel); if (Paging.ContinuationToken != null || NextPagePropertyType.Equals(typeof(Uri))) { diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Snippets/JsonTokenTypeSnippets.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Snippets/JsonTokenTypeSnippets.cs index b76e97adcf1..5642946557f 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Snippets/JsonTokenTypeSnippets.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Snippets/JsonTokenTypeSnippets.cs @@ -14,5 +14,6 @@ internal static class JsonTokenTypeSnippets public static ValueExpression StartObject => FrameworkEnumValue(JsonTokenType.StartObject); public static ValueExpression EndObject => FrameworkEnumValue(JsonTokenType.EndObject); public static ValueExpression Null => FrameworkEnumValue(JsonTokenType.Null); + public static ValueExpression PropertyName => FrameworkEnumValue(JsonTokenType.PropertyName); } } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Snippets/Utf8JsonReaderSnippets.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Snippets/Utf8JsonReaderSnippets.cs index 6672311afe5..89a430c9717 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Snippets/Utf8JsonReaderSnippets.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Snippets/Utf8JsonReaderSnippets.cs @@ -43,5 +43,11 @@ public static InvokeMethodExpression GetDateTimeOffset(this VariableExpression r public static InvokeMethodExpression GetGuid(this VariableExpression reader) => reader.Invoke(nameof(Utf8JsonReader.GetGuid)); + + public static InvokeMethodExpression ValueTextEquals(this VariableExpression reader, string text) + => reader.Invoke(nameof(Utf8JsonReader.ValueTextEquals), Literal(text)); + + public static InvokeMethodExpression Skip(this VariableExpression reader) + => reader.Invoke(nameof(Utf8JsonReader.Skip)); } } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBody.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBody.cs index 5b46c63769f..09a34c33879 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBody.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBody.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -32,7 +32,23 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options)); yield return result; - nextToken = ((global::Sample.Models.Page)result).NextPage; + nextToken = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextPage"))) + { + reader.Read(); + nextToken = reader.GetString(); + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if (string.IsNullOrEmpty(nextToken)) { yield break; @@ -43,7 +59,23 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - string nextPage = ((global::Sample.Models.Page)page).NextPage; + string nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextPage"))) + { + reader.Read(); + nextPage = reader.GetString(); + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if (!string.IsNullOrEmpty(nextPage)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBodyAsync.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBodyAsync.cs index 7d72955fb56..62b81dacd82 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBodyAsync.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBodyAsync.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -32,7 +32,23 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false)); yield return result; - nextToken = ((global::Sample.Models.Page)result).NextPage; + nextToken = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextPage"))) + { + reader.Read(); + nextToken = reader.GetString(); + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if (string.IsNullOrEmpty(nextToken)) { yield break; @@ -43,7 +59,23 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - string nextPage = ((global::Sample.Models.Page)page).NextPage; + string nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextPage"))) + { + reader.Read(); + nextPage = reader.GetString(); + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if (!string.IsNullOrEmpty(nextPage)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBody.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBody.cs index cebf8a007c8..6d3604c9d55 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBody.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBody.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -32,7 +32,38 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options)); yield return result; - nextToken = ((global::Sample.Models.Page)result).NestedNext?.NextPage; + nextToken = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nestedNext"))) + { + reader.Read(); + if ((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject)) + { + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextPage"))) + { + reader.Read(); + nextToken = reader.GetString(); + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if (string.IsNullOrEmpty(nextToken)) { yield break; @@ -43,7 +74,38 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - string nextPage = ((global::Sample.Models.Page)page).NestedNext?.NextPage; + string nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nestedNext"))) + { + reader.Read(); + if ((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject)) + { + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextPage"))) + { + reader.Read(); + nextPage = reader.GetString(); + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if (!string.IsNullOrEmpty(nextPage)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBodyAsync.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBodyAsync.cs index c6a3bddf38f..bf99dd3c48b 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBodyAsync.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBodyAsync.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -32,7 +32,38 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false)); yield return result; - nextToken = ((global::Sample.Models.Page)result).NestedNext?.NextPage; + nextToken = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nestedNext"))) + { + reader.Read(); + if ((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject)) + { + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextPage"))) + { + reader.Read(); + nextToken = reader.GetString(); + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if (string.IsNullOrEmpty(nextToken)) { yield break; @@ -43,7 +74,38 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - string nextPage = ((global::Sample.Models.Page)page).NestedNext?.NextPage; + string nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nestedNext"))) + { + reader.Read(); + if ((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject)) + { + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextPage"))) + { + reader.Read(); + nextPage = reader.GetString(); + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if (!string.IsNullOrEmpty(nextPage)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBody.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBody.cs index e1f78cc8679..ded98342a5b 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBody.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBody.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -30,7 +30,27 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, global: global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options)); yield return result; - nextPageUri = ((global::Sample.Models.Page)result).NextCat; + nextPageUri = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPageUri = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPageUri == null)) { yield break; @@ -41,7 +61,27 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, global: public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - global::System.Uri nextPage = ((global::Sample.Models.Page)page).NextCat; + global::System.Uri nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPage = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPage != null)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage.IsAbsoluteUri ? nextPage.AbsoluteUri : nextPage.OriginalString)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBodyAsync.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBodyAsync.cs index 0491709e3c8..fa5e07d6c60 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBodyAsync.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBodyAsync.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -30,7 +30,27 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, gl global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false)); yield return result; - nextPageUri = ((global::Sample.Models.Page)result).NextCat; + nextPageUri = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPageUri = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPageUri == null)) { yield break; @@ -41,7 +61,27 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, gl public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - global::System.Uri nextPage = ((global::Sample.Models.Page)page).NextCat; + global::System.Uri nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPage = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPage != null)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage.IsAbsoluteUri ? nextPage.AbsoluteUri : nextPage.OriginalString)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBody.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBody.cs index 0b2e4c398a3..ca42b7869e9 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBody.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBody.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -30,7 +30,42 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, global: global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options)); yield return result; - nextPageUri = ((global::Sample.Models.Page)result).NestedNext?.NextCat; + nextPageUri = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nestedNext"))) + { + reader.Read(); + if ((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject)) + { + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPageUri = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPageUri == null)) { yield break; @@ -41,7 +76,42 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, global: public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - global::System.Uri nextPage = ((global::Sample.Models.Page)page).NestedNext?.NextCat; + global::System.Uri nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nestedNext"))) + { + reader.Read(); + if ((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject)) + { + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPage = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPage != null)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage.IsAbsoluteUri ? nextPage.AbsoluteUri : nextPage.OriginalString)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBodyAsync.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBodyAsync.cs index 82f8d0a8341..979be00f296 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBodyAsync.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBodyAsync.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -30,7 +30,42 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, gl global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false)); yield return result; - nextPageUri = ((global::Sample.Models.Page)result).NestedNext?.NextCat; + nextPageUri = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nestedNext"))) + { + reader.Read(); + if ((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject)) + { + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPageUri = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPageUri == null)) { yield break; @@ -41,7 +76,42 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, gl public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - global::System.Uri nextPage = ((global::Sample.Models.Page)page).NestedNext?.NextCat; + global::System.Uri nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nestedNext"))) + { + reader.Read(); + if ((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject)) + { + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPage = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPage != null)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage.IsAbsoluteUri ? nextPage.AbsoluteUri : nextPage.OriginalString)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBody.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBody.cs index e1f78cc8679..ded98342a5b 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBody.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBody.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -30,7 +30,27 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, global: global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options)); yield return result; - nextPageUri = ((global::Sample.Models.Page)result).NextCat; + nextPageUri = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPageUri = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPageUri == null)) { yield break; @@ -41,7 +61,27 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, global: public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - global::System.Uri nextPage = ((global::Sample.Models.Page)page).NextCat; + global::System.Uri nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPage = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPage != null)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage.IsAbsoluteUri ? nextPage.AbsoluteUri : nextPage.OriginalString)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBodyAsync.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBodyAsync.cs index 0491709e3c8..fa5e07d6c60 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBodyAsync.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBodyAsync.cs @@ -6,7 +6,7 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using Sample.Models; +using System.Text.Json; namespace Sample { @@ -30,7 +30,27 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, gl global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false)); yield return result; - nextPageUri = ((global::Sample.Models.Page)result).NextCat; + nextPageUri = null; + global::System.BinaryData data = result.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPageUri = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPageUri == null)) { yield break; @@ -41,7 +61,27 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, gl public override global::System.ClientModel.ContinuationToken GetContinuationToken(global::System.ClientModel.ClientResult page) { - global::System.Uri nextPage = ((global::Sample.Models.Page)page).NextCat; + global::System.Uri nextPage = null; + global::System.BinaryData data = page.GetRawResponse().Content; + global::System.Text.Json.Utf8JsonReader reader = new global::System.Text.Json.Utf8JsonReader(data.ToMemory().Span); + reader.Read(); + while (reader.Read()) + { + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.PropertyName) && reader.ValueTextEquals("nextCat"))) + { + reader.Read(); + string nextPageStr = reader.GetString(); + if (!string.IsNullOrEmpty(nextPageStr)) + { + nextPage = new global::System.Uri(nextPageStr, global::System.UriKind.RelativeOrAbsolute); + } + break; + } + if (((reader.TokenType == global::System.Text.Json.JsonTokenType.StartObject) || (reader.TokenType == global::System.Text.Json.JsonTokenType.StartArray))) + { + reader.Skip(); + } + } if ((nextPage != null)) { return global::System.ClientModel.ContinuationToken.FromBytes(global::System.BinaryData.FromString(nextPage.IsAbsoluteUri ? nextPage.AbsoluteUri : nextPage.OriginalString)); diff --git a/packages/http-client-csharp/global.json b/packages/http-client-csharp/global.json index 311edc2181a..7be862f576b 100644 --- a/packages/http-client-csharp/global.json +++ b/packages/http-client-csharp/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "10.0.103", + "version": "10.0.102", "rollForward": "feature" } }