-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Update to latest version 2023-10-31 #45151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
dc60072
5450906
07e1d2e
0192362
a62453c
38c751e
95a15f8
9cd214f
2c518d4
4e92dff
752f822
f15852e
73d5d68
f489988
b6f9929
3fce130
0cb71e1
16fce34
93e74df
3dbb979
ad3ba37
210951b
0951943
26074cf
fd92d63
076ebf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,12 +46,17 @@ | |
import com.azure.digitaltwins.core.models.UpdateComponentOptions; | ||
import com.azure.digitaltwins.core.models.UpdateDigitalTwinOptions; | ||
import com.azure.digitaltwins.core.models.UpdateRelationshipOptions; | ||
import com.azure.json.JsonProviders; | ||
import com.azure.json.JsonReader; | ||
import com.azure.json.JsonWriter; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.io.UncheckedIOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -1541,7 +1546,23 @@ <T> Mono<PagedResponse<T>> queryNextPage(String nextLink, Class<T> clazz, QueryO | |
context = Context.NONE; | ||
} | ||
|
||
QuerySpecification querySpecification = new QuerySpecification().setContinuationToken(nextLink); | ||
// The nextLink continuation token is a stringified JSON object. Attempt to deserialize the nextLink into any | ||
// Object and inspect whether is what a stringified JSON value (List = array, Map = object, String = string). | ||
// If it was a stringified value, use nextLink as-is. If not, serialize the nextLink into a JSON string. | ||
String nextLinkToUse; | ||
try (JsonReader jsonReader = JsonProviders.createReader(nextLink)) { | ||
Object untyped = jsonReader.readUntyped(); | ||
|
||
if (untyped instanceof List || untyped instanceof Map || untyped instanceof String) { | ||
nextLinkToUse = nextLink; | ||
} else { | ||
nextLinkToUse = serializeNextLink(nextLink); | ||
} | ||
} catch (IOException ex) { | ||
nextLinkToUse = serializeNextLink(nextLink); | ||
} | ||
|
||
QuerySpecification querySpecification = new QuerySpecification().setContinuationToken(nextLinkToUse); | ||
Comment on lines
+1552
to
+1565
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was the nextLink changed? Is this backward compatible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alzimmermsft has more context on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @srnagar, yes, this change was needed to maintain a piece of backwards compatibility after Digital Twins was migrated to azure-json. Effectively, a lot of the original Digital Twins SDK was developed with "anything" can be passed so there are a lot of checks to validate and appropriately handle customer inputs. This is just a check for that on the continuation token. |
||
|
||
return protocolLayer.getQueries() | ||
.queryTwinsWithResponseAsync(querySpecification, OptionsConverter.toProtocolLayerOptions(options), context) | ||
|
@@ -1557,6 +1578,15 @@ <T> Mono<PagedResponse<T>> queryNextPage(String nextLink, Class<T> clazz, QueryO | |
objectPagedResponse.getDeserializedHeaders())); | ||
} | ||
|
||
private static String serializeNextLink(String nextLink) { | ||
try (StringWriter writer = new StringWriter(); JsonWriter jsonWriter = JsonProviders.createWriter(writer)) { | ||
jsonWriter.writeString(nextLink); | ||
return writer.toString(); | ||
} catch (IOException ex) { | ||
throw LOGGER.logExceptionAsError(new UncheckedIOException(ex)); | ||
} | ||
} | ||
|
||
//endregion Query APIs | ||
|
||
//region Event Route APIs | ||
|
@@ -2056,7 +2086,8 @@ private static DigitalTwinsResponseHeaders createDTResponseHeadersFromResponse(R | |
: new DigitalTwinsResponseHeaders().setETag(response.getHeaders().getValue(HttpHeaderName.ETAG)); | ||
} | ||
|
||
private <T> Mono<DigitalTwinsResponse<T>> deserializeHelper(Response<Object> response, Class<T> clazz) { | ||
private <T> Mono<DigitalTwinsResponse<T>> deserializeHelper(Response<Map<String, Object>> response, | ||
Class<T> clazz) { | ||
try { | ||
T genericResponse = DeserializationHelpers.deserializeObject(protocolLayer.getSerializerAdapter(), | ||
response.getValue(), clazz, this.serializer); | ||
|
Uh oh!
There was an error while loading. Please reload this page.