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

feat: add type handlers for SimpleUri and BlockUri #5061

Merged
merged 11 commits into from
Aug 23, 2022

Conversation

jdrueckert
Copy link
Member

@jdrueckert jdrueckert commented Aug 15, 2022

Contains

New type handlers to support de-/serializing to/from SimpleUri and BlockUri.

How to test

Can be tested in combination with Terasology/ChangingBlocks#15.

@jdrueckert jdrueckert added Type: Improvement Request for or addition/enhancement of a feature Size: S Small effort likely only affecting a single area and requiring little to no research labels Aug 15, 2022
@jdrueckert jdrueckert requested a review from keturn August 15, 2022 20:59
Comment on lines 20 to 21
public SimpleUri getFromString(String representation) {
return new SimpleUri(representation);
Copy link
Member

Choose a reason for hiding this comment

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

Lets add a check of uri.isValid() here. It's a cheap check, and doing it here instead of leaving it until later will make it easier to identify what the source string is and where it came from.

As for what we do if it doesn't pass the check... uh, if we think the deserialization code is trying to avoid throwing exceptions, I guess we log the error but still return the invalid SimpleUri instance?

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the implementation of StringRepresentationTypeHandler returning null would yield Optional.empty, which is our equivalent to "could not parse"... That probably better than returning an invlid SimpleUri...

public SimpleUri getFromString(String representation) {
SimpleUri uri = new SimpleUri(representation);
if (!uri.isValid()) {
logger.error("Failed to create valid SimpleURI from string '{}'", representation);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger.error("Failed to create valid SimpleURI from string '{}'", representation);
logger.error("Failed to create valid SimpleURI from string '{}'", representation);
// StringRepresentationTypeHandler will turn this 'null' value into an empty Optional
return null;

Copy link
Member Author

Choose a reason for hiding this comment

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

done ✔️

also added tests

- will result in empty optional indicating parsing / deserialization error
Copy link
Member

@keturn keturn left a comment

Choose a reason for hiding this comment

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

[Oops, duplicate comment.]

keturn
keturn previously approved these changes Aug 21, 2022
Copy link
Member

@keturn keturn left a comment

Choose a reason for hiding this comment

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

I think this looks good.

I was thinking a bit about what kind of test would be appropriate. I don't think SimpleUriTypeHandler would benefit from any additional tests to its methods, but maybe we could add an integration test one level higher up that demonstrates we can use SimpleUri with the default TypeHandlerLibrary? Would that be useful?

[Approving but not merging yet because the Release Candidate has already been cut and I'm not clear on which things need to go in this release.]

@jdrueckert
Copy link
Member Author

maybe we could add an integration test one level higher up that demonstrates we can use SimpleUri with the default TypeHandlerLibrary? Would that be useful?

Could be but I'd argue that that would be a suitable consideration for the upcoming type handler improvements when we look at the contracts of the type handlers.

@jdrueckert
Copy link
Member Author

As discussed in the contributor meeting, I added a type handler for BlockUri.

@jdrueckert jdrueckert dismissed skaldarnar’s stale review August 21, 2022 22:53

requested changes added

keturn
keturn previously requested changes Aug 22, 2022
Copy link
Member

@keturn keturn left a comment

Choose a reason for hiding this comment

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

one small correction; feel free to merge after adding that if it works with your ChangingBlocks use case.

@@ -113,6 +115,7 @@ private static void populateWithDefaultHandlers(TypeHandlerLibrary serialization
serializationLibrary.addTypeHandlerFactory(new AssetTypeHandlerFactory());

serializationLibrary.addTypeHandler(Name.class, new NameTypeHandler());
serializationLibrary.addTypeHandler(SimpleUri.class, new SimpleUriTypeHandler());
Copy link
Member

Choose a reason for hiding this comment

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

We'll want to add BlockUri's handler here too, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch, thank you! will add that later today 👍

@jdrueckert
Copy link
Member Author

one small correction; feel free to merge after adding that if it works with your ChangingBlocks use case.

correction added and tested, works fine for the ChangingBlocks use case using ChangingBlocks#15 and PlantPack#20 👍

@jdrueckert jdrueckert dismissed keturn’s stale review August 22, 2022 22:16

correction added

@jdrueckert jdrueckert changed the title feat: add type handler for SimpleUri feat: add type handlers for SimpleUri and BlockUri Aug 23, 2022
@jdrueckert jdrueckert merged commit 03023ad into develop Aug 23, 2022
@jdrueckert jdrueckert deleted the feat/add-simpleuri-typehandler branch August 23, 2022 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: S Small effort likely only affecting a single area and requiring little to no research Type: Improvement Request for or addition/enhancement of a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants