-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
JsonSerializer.Deserialize<T>() not work #82016
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsDescriptionThe JSON file content:Code:public record ApiConfig {
public string AppUrl { get; init; } = string.Empty;
public string AuthenticationEndPoint { get; init; } = string.Empty;
public string TokenEndPoint { get; init; } = string.Empty;
public string AppKey { get; init; } = string.Empty;
public string OpenApiBaseUrl { get; init; } = string.Empty;
public string StreamingUrl { get; set; } = string.Empty;
}
public class Settings {
public ApiConfig OpenApiConfig { get; } = new();
} var text = ... // json content as above
// Why settings all properties are empty?
var settings = JsonSerializer.Deserialize<Settings>(text) ?? throw new InvalidDataException(...); Reproduction StepsAs my code. Expected behaviorThe Actual behaviorThe Regression?No response Known WorkaroundsNo response Configuration.NET: Other informationNo response
|
... If these settings are for your own application, there are existing libraries for binding configuration. That said, this is because public class Settings {
public ApiConfig OpenApiConfig { get; init; } = new();
} |
God, there is still a gap between |
Description
The
JsonSerializer.Deserialize<T>
not fill properties ofSettings
.JSON file content:
Code:
Reproduction Steps
As my code.
Expected behavior
The
settings
returned byJsonSerializer.Deserialize<T>
be filled.Actual behavior
The
settings
properties all keep empty.Regression?
No response
Known Workarounds
No response
Configuration
.NET:
7.0.2
OS:
10.0.22621.0
Other information
No response
The text was updated successfully, but these errors were encountered: