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

Support default values when building serialization functions #7

Closed
dstelljes opened this issue Aug 21, 2019 · 4 comments · Fixed by #182
Closed

Support default values when building serialization functions #7

dstelljes opened this issue Aug 21, 2019 · 4 comments · Fixed by #182
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@dstelljes
Copy link
Member

Open questions:

  • The serializer builder currently throws when a field on a record does not have a matching property on the .NET type being mapped. If a default value were used instead, would that obscure errors (like typos on member names)?

  • How would default values be represented on the Schema class?

@dstelljes dstelljes added enhancement New feature or request help wanted Extra attention is needed labels Aug 21, 2019
@kingwill27
Copy link
Contributor

@dstelljes We are running into an issue with schemas created from .NET types where the default values that are declared on the class properties don't get translated to the schema, i.e.

public class Message
{
  public int? Property { get; set; } = null;
}

generates the schema {"name":"Message","type":"record","fields":[{"name":"Property","type":["null","int"]}]} without the default field.

Is this related to this serialization issue? I also see that this is tagged as "help wanted" and may be able to help work on it if given some direction.

@dstelljes
Copy link
Member Author

It’s somewhat related—this issue specifically relates to support for "default" values when building serializers.

Your use case is tricky because there isn’t any reliable way to get the default .NET value when building a schema: In your example, null is assigned to Property when Message is constructed; it’s not a constant value that can be obtained by reflecting on the class.

@digitalpacman
Copy link

What about just relying on the [DefaultValue] attribute

@dstelljes dstelljes removed the help wanted Extra attention is needed label Dec 16, 2020
@dstelljes dstelljes added this to the 8.0.0 milestone Dec 16, 2020
@dstelljes dstelljes self-assigned this Dec 16, 2020
@dstelljes dstelljes linked a pull request Feb 8, 2022 that will close this issue
@dstelljes
Copy link
Member Author

Released in 8.0.0-pre.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants