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

Introduce PolymorphismStyle.None #494

Merged
merged 7 commits into from
Jan 14, 2024

Conversation

ZacSweers
Copy link
Contributor

This implements #378 by introducing a new None style that omits the tag/property entirely from the output yaml.

Note this is asymmetric and reads are treated the same as Tag as reads require a tag.

I added a few tests to JvmYamlWritingTest for both this case and some added coverage for the existing two cases as well.

This implements charleskorn#378 by introducing a new `None` style that omits the tag/property entirely from the output yaml.

Note this is asymmetric and reads are treated the same as `Tag` as reads require a tag.

I added a few tests to JvmYamlWritingTest for both this case and some added coverage for the existing two cases as well.
@ZacSweers ZacSweers mentioned this pull request Dec 14, 2023
Copy link
Owner

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @ZacSweers!

Overall, this looks good to me.

In addition to the comment below, could you please also add a test for the behaviour when reading polymorphic and non-polymorphic content while PolymorphismStyle.None is in use?

Comment on lines 66 to 75
PolymorphismStyle.Tag -> throw MissingTypeTagException(node.path)
PolymorphismStyle.Tag, PolymorphismStyle.None -> throw MissingTypeTagException(node.path)
PolymorphismStyle.Property -> createPolymorphicMapDeserializer(node, yaml, context, configuration)
}
else -> throw IncorrectTypeException("Expected ${descriptor.kind.friendlyDescription}, but got a map", node.path)
}

is YamlTaggedNode -> when {
descriptor.kind is PolymorphicKind && configuration.polymorphismStyle == PolymorphismStyle.Tag -> YamlPolymorphicInput(node.tag, node.path, node.innerNode, yaml, context, configuration)
descriptor.kind is PolymorphicKind && configuration.polymorphismStyle != PolymorphismStyle.Property -> {
YamlPolymorphicInput(node.tag, node.path, node.innerNode, yaml, context, configuration)
}
Copy link
Owner

Choose a reason for hiding this comment

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

I think it might be simpler to just fail if we encounter polymorphism or a tag and PolymorphismStyle.None is in use.

@mgroth0
Copy link

mgroth0 commented Dec 29, 2023

Thank you for working on this! I really appreciate it :)

@ZacSweers
Copy link
Contributor Author

Will look when I'm back from vacation 👍

@ZacSweers
Copy link
Contributor Author

Done!

Copy link
Owner

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

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

Thanks @ZacSweers! I've got some minor nits for the test names, but I'll update the branch and then merge this - thanks again for the PR.

@charleskorn charleskorn merged commit 2f0de20 into charleskorn:main Jan 14, 2024
1 check passed
@ZacSweers ZacSweers deleted the z/nonePolymorphism branch January 16, 2024 19:04
@ZacSweers
Copy link
Contributor Author

ZacSweers commented Jan 16, 2024

I think there's a bug that I missed in YamlOutput here:

if (tag.isPresent && configuration.polymorphismStyle != PolymorphismStyle.Tag) {
throw IllegalStateException("Cannot serialize a polymorphic value that is not a YAML object when using ${PolymorphismStyle::class.simpleName}.${configuration.polymorphismStyle}.")
}

I think in the None case, it should just omit the tag right? If so, I can PR a quick fix

@charleskorn
Copy link
Owner

I think there's a bug that I missed in YamlOutput here:

if (tag.isPresent && configuration.polymorphismStyle != PolymorphismStyle.Tag) {
throw IllegalStateException("Cannot serialize a polymorphic value that is not a YAML object when using ${PolymorphismStyle::class.simpleName}.${configuration.polymorphismStyle}.")
}

I think in the None case, it should just omit the tag right? If so, I can PR a quick fix

That makes sense to me - a PR with a test case and fix would be great.

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