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

JsonProperty required allowed but not respected on record parameters #2951

Open
mikethea1 opened this issue Apr 30, 2024 · 2 comments
Open

Comments

@mikethea1
Copy link

Source/destination types

record R([JsonProperty(Required = Required.Always)] string A, [JsonProperty(Required = Required.Always)] string[] B);

Source/destination JSON

{}

Expected behavior

Deserialization error because the required properties were not present.

Actual behavior

Deserializes successfully with all properties null.

Steps to reproduce

JsonConvert.DeserializeObject<R>("{}");
@MO2k4
Copy link

MO2k4 commented Apr 30, 2024

Your attribute is invalid, try to use [property:JsonProperty...]

@elgonzo
Copy link

elgonzo commented Apr 30, 2024

@MO2k4

No, the application of the attribute as shown is not invalid. It's meant to support constructor parameters:

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false)]
public sealed class JsonPropertyAttribute : Attribute

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

No branches or pull requests

3 participants