Skip to content

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


// 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
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.

4 participants