Skip to content
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

Fix digital twins client not deserializing date times correctly #16975

Merged
merged 5 commits into from
Oct 29, 2020

Conversation

timtay-microsoft
Copy link
Member

@timtay-microsoft timtay-microsoft commented Oct 29, 2020

Also fix BasicDigitalTwinMetadata to use the DigitalTwinPropertyMetadata class

Also mark DigitalTwinPropertyMetadata as fluent and final as per Azure SDK feedback

For some context:
#16938

Also fix BasicDigitalTwinMetadata to use the DigitalTwinPropertyMetadata class

JacksonAdapter jacksonAdapter = new JacksonAdapter();
mapper = jacksonAdapter.serializer(); // Use the same mapper in this layer that the generated layer will use
stringModule.addSerializer(new DigitalTwinsStringSerializer(String.class, mapper));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was that we used a different mapper in our convenience layer than we did in our generated layer. The generated layer one (from jacksonAdapter.serializer()) has a lot of useful modules registered already, including a module for parsing of date times. By simply using the generated layer's adapter in this layer as well, this issue is solved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this mapper is not to be confused with the custom serializer that users can provide. If the user provides a custom serializer, then this mapper won't be used in the convenience layer

@@ -46,6 +51,10 @@ public static void main(String[] args) throws IOException {
.setLogLevel(parsedArguments.getHttpLogDetailLevel()))
.buildClient();

// This mapper gets used to deserialize a digital twin that has a date time within a property metadata, so it
// needs to have this module in order to correctly deserialize that date time
mapper.registerModule(new JavaTimeModule());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the module that was missing from our default mapper in the digital twins client. We get this module for free when we construct the JacksonAdapter and call .serializer() on that jacksonAdapter. We need to explicitly use it here, though


JacksonAdapter jacksonAdapter = new JacksonAdapter();
mapper = jacksonAdapter.serializer(); // Use the same mapper in this layer that the generated layer will use
stringModule.addSerializer(new DigitalTwinsStringSerializer(String.class, mapper));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this string serializer? Are there any APIs that still operate on Strings? I thought we got rid of all those, and everything was objects now.

Copy link
Member Author

@timtay-microsoft timtay-microsoft Oct 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the plan back when we were going to force APIs to take in a <T extends IDigitalTwin>, but those plans fell through, so we're back to supporting strings again. It would be more work to remove them at this point then I think it would be worth

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, so now we are back to the original state where we support <T> as String as input for these APIs.

@timtay-microsoft timtay-microsoft merged commit 15e7cf0 into master Oct 29, 2020
@timtay-microsoft timtay-microsoft deleted the feature/adt/timtay/propertyMetadata branch October 29, 2020 23:43
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-java that referenced this pull request Dec 9, 2021
arnavshringi-patch-1 (Azure#16975)

* Added "readonly" in 2021-03-01-preview

* Added "readonly" in 2021-09-01
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-java that referenced this pull request Jan 5, 2022
arnavshringi-patch-1 (Azure#16975)

* Added "readonly" in 2021-03-01-preview

* Added "readonly" in 2021-09-01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants