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

Uppercase #110446

Closed
EbGu3 opened this issue Dec 5, 2024 · 5 comments
Closed

Uppercase #110446

EbGu3 opened this issue Dec 5, 2024 · 5 comments

Comments

@EbGu3
Copy link

EbGu3 commented Dec 5, 2024

Description

Bug en deserializar

  • La api me responde el contenido del api response pero no lo deserializa. Por lo que procedí a crear el objeto que estoy recibiendo y serializarlo. lo único diferente que observo son las mayúsculas. El nugget de Newtonsoft.Json lo hace sin ningún problema, pero System.Text.Json no

  • api response

{
   "result":{
      "actualizada":true
   },
   "message":"¡Tabla, actualizada!",
   "description":"",
   "statusCode":200
}
  • objeto seralizado
{
   "Result":{
      "Actualizada":false
   },
   "Message":"",
   "Description":"",
   "StatusCode":0
}
  • clase
    public class ResponseGeneric<T>
    {
        public required T Result    { get; set; }
        public string Message       { get; set; } = string.Empty;
        public string Description   { get; set; } = string.Empty;
        public int StatusCode       { get; set; }
    }

    public class Resultado
    {
        public bool Actualizado { get; set; }
    }

Reproduction Steps

  1. Realize una consulta a una api de c# en .net 8 usando el nugget RestClientOptions
  2. Uso JsonSerializer.Deserialize para extraer la respuesta de la api

Expected behavior

Actual behavior

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 5, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@Miizukii
Copy link
Contributor

Miizukii commented Dec 5, 2024

https://learn.microsoft.com/dotnet/standard/serialization/system-text-json/character-casing

var options = new JsonSerializerOptions
{
    PropertyNameCaseInsensitive = true
};
WeatherForecast? weatherForecast = JsonSerializer.Deserialize<WeatherForecast>(jsonString, options);

@EbGu3
Copy link
Author

EbGu3 commented Dec 5, 2024

Entiendo, agradezco. 🤭👍
Aun que siento que debe de ser un punto de mejora para la librería. Porque si lo uso 10 veces lo tendría que duplicar 10 veces.

@Miizukii
Copy link
Contributor

Miizukii commented Dec 5, 2024

You can create it once and reuse it.
https://learn.microsoft.com/dotnet/standard/serialization/system-text-json/configure-options#reuse-jsonserializeroptions-instances

@eiriktsarpalis
Copy link
Member

Closing as answered.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants