Comments (6)
Hey, thank for the question! Looks like your request file is missing a quote on line 14. Maybe that's the issue?
If I don't hear back from you tonight I'll look into it deeper and create a sample once I figure it out.
from dunet.
Looks like the issue is the extra quote in https://github.com/titouancreach/repro-dunet/blob/main/Repro.http#L14C20-L14C20. Worked fine for me once I removed it.
from dunet.
Oh sure you are right ! I need to update my repro repo because I have an issue in my "real" repo (and I hope it's not a quote since I spent several hours on it) 😮. I will reopen with a proper repro. Thanks you very miche for your reactivity, I appreciate !
from dunet.
Ohh once I removed the quote, I got the error I have in my real code:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Shape'. Path: $.param | LineNumber: 0 | BytePositionInLine: 20.
---> System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Shape'.
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ThrowNotSupportedException(ReadStack& state, Utf8JsonReader& reader, NotSupportedException ex)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
at System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5.TryRead[TArg](ReadStack& state, Utf8JsonReader& reader, JsonParameterInfo jsonParameterInfo, TArg& arg)
at System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5.ReadAndCacheConstructorArgument(ReadStack& state, Utf8JsonReader& reader, JsonParameterInfo jsonParameterInfo)
at System.Text.Json.Serialization.Converters.ObjectWithParameterizedConstructorConverter`1.ReadConstructorArgumentsWithContinuation(ReadStack& state, Utf8JsonReader& reader, JsonSerializerOptions options)
at System.Text.Json.Serialization.Converters.ObjectWithParameterizedConstructorConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsync(Stream utf8Json, CancellationToken cancellationToken)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObjectAsync(Stream utf8Json, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.HttpRequestJsonExtensions.ReadFromJsonAsync(HttpRequest request, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.HttpRequestJsonExtensions.ReadFromJsonAsync(HttpRequest request, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<HandleRequestBodyAndCompileRequestDelegateForJson>g__TryReadBodyAsync|94_0(HttpContext httpContext, Type bodyType, String parameterTypeName, String parameterName, Boolean allowEmptyRequestBody, Boolean throwOnBadRequest, JsonTypeInfo jsonTypeInfo)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass94_2.<<HandleRequestBodyAndCompileRequestDelegateForJson>b__2>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
How did you make it work ?
Edit1:
Postman generate this request:
curl --location 'http://localhost:5237/du/' \
--header 'Content-Type: application/json' \
--data '{
"param": {
"$type": "Circle",
"radius": 45
}
}
'
and it works
and my vim plugin generate:
curl -sSL --compressed -X 'POST' -H 'Content-Type: application/json' --data-raw '{"param": {"radius": 45, "$type": "Circle"}}' 'localhost:5237/du/'
that doesn't work
Edit2:
Ok I want to die, actually the order is important, "$type" should be first !
Should we put this in the Readme or in a comment in the example ? I literally wasted like 4h/5h of debug
https://stackoverflow.com/questions/16870416/does-the-sequence-of-the-values-matter-in-a-json-object
from dunet.
Oh, man. That must not have been fun to troubleshoot. Thanks for taking the time. I've created a PR updating the relevant sample and readme with that information. Hopefully others don't run into the same issue.
from dunet.
Yes, I made some tests, and without Dunet, the message is kind of explicit (it tells you $type should be present and first) but with Dunet, the message is shadowed.
Thanks for making it clear in the readme :)
from dunet.
Related Issues (20)
- Inner union compile with error `Cannot implicitly convert type 'X' to 'Y` HOT 6
- Async match support HOT 2
- Add `Action` based `Match` (or similarly named) method HOT 5
- Async Action Match
- Do not generate implicit conversions if argument is an interface
- Disable CS1591 in generated code
- Record struct union support HOT 8
- Anonymous union variants
- Match on a specific union value only
- Unwrap union types HOT 2
- Simplify instantiation of generic-bound union members HOT 1
- Idea: Friendly use of ToString() HOT 4
- Make common members accessible without matching HOT 4
- Allow matching with static functions
- Implicit conversions clash with required union properties HOT 1
- Separate Attributes into another project HOT 4
- Prefer `_ is _ _` pattern HOT 1
- Add Action with the type in the else of a MatchXYZ HOT 7
- Annotate Generated Code with GeneratedCodeAttribute
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dunet.