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

system.text.json ignores [JsonConverter(..)] on [FromQuery] in ASP.NET #38939

Closed
jamalabo1 opened this issue Jul 8, 2020 · 6 comments
Closed
Assignees
Labels
area-System.Text.Json needs-author-action An issue or pull request that requires more info or actions from the author.
Milestone

Comments

@jamalabo1
Copy link

   public class MyClass
   {
       [JsonConverter(typeof(CustomBreakConverter))] 
       public IEnumerable<MyRange<DateTimeOffset>> Break { get; set; }
   }

Custom converter:

    public class CustomBreakConverter : JsonConverter<IEnumerable<MyRange<DateTimeOffset>>>
    {
        public override IEnumerable<MyRange<DateTimeOffset>> Read(ref Utf8JsonReader reader,
            Type typeToConvert,
            JsonSerializerOptions options)
        {
            ...
        }

        public override void Write(Utf8JsonWriter writer, IEnumerable<MyRange<DateTimeOffset>> value,
            JsonSerializerOptions options)
        {
           ...
        }
    }

Controller

        [HttpGet]
        [Route("route")]
        public async Task<IActionResult> Get([FromQuery] MyClass data)
        {
           ...
        }

when the request is GET it ignores the custom converter, (throws an error (cannot deserialize) and does not reach the code (debugged))

        [HttpPost]
        [Route("route")]
        public async Task<IActionResult> Get([FromBody] MyClass data)
        {
           ...
        }

when the controller is this it works

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Jul 8, 2020
@layomia layomia removed the untriaged New issue has not been triaged by the area owner label Jul 10, 2020
@layomia layomia added this to the 5.0.0 milestone Jul 10, 2020
@layomia
Copy link
Contributor

layomia commented Jul 10, 2020

Duplicate of #33112.

@jamalabo1
Copy link
Author

but the "interface" works with POST requests, is it part of the unexpected behavior?

@layomia
Copy link
Contributor

layomia commented Jul 31, 2020

@jamalabo1, can you share a small project that highlights the issue? This would include the implementation of the custom converter.

@layomia layomia self-assigned this Jul 31, 2020
@layomia layomia modified the milestones: 5.0.0, Future Aug 15, 2020
@layomia
Copy link
Contributor

layomia commented Aug 15, 2020

@jamalabo1 - I couldn't repro any errors on .NET Core 3.1 or .NET 5.0 here given the issue description and the provided code samples. Please take a look at my repro to see if it correctly captures the scenario you have - https://dotnetfiddle.net/rm05JE.

I'm going to move this issue to future since it is not actionable as currently reported. We can triage again if needed. If your issue is not solved, please provide a simple console/ASP.NET Core project that shows a repro so that we can determine if there's a problem with System.Text.Json or with ASP.NET Core.

@ghost
Copy link

ghost commented Nov 3, 2021

This issue has been automatically marked no recent activity because it has been marked as needs more info but has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no recent activity.

Please refer to our contribution guidelines for tips on what information might be required.

@ghost
Copy link

ghost commented Nov 17, 2021

This issue will now be closed since it had been marked no recent activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@ghost ghost closed this as completed Nov 17, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Dec 17, 2021
@eiriktsarpalis eiriktsarpalis added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jan 19, 2022
@ghost ghost removed the no-recent-activity label Jan 19, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json needs-author-action An issue or pull request that requires more info or actions from the author.
Projects
None yet
Development

No branches or pull requests

5 participants