✅ RestAPI getting an error while testing (TimeSpan related)
I thought to have solved this, but it's not.
As title, I'm testing some written RestAPI (still in development) for a service.
The project is in .NET 7.0
There are few fields to type plus a field that will put in a DB hours and minutes, example 10:00
Well, in the model definition I have this:
Well, when I launch the debug, and it open Swaggler, I type all fields, and finally I have to write this TestHour.
I tried with:
- 10:00
- 10:00:00
- 360000000000
- 360000000000, 0, 0
None of those worked, and I get the following error from Swaggler:
The JSON value could not be converted to System.TimeSpan
Someone knows what could be?
Am I doing something wrong, or maybe something doesn't works with this .NET ver?32 Replies
Well, I tried changing definition to
Also if I not was asked to change models, I made it for try understand if my input was bad, then, now it clearly ask me for "Hour" and "Minutes", I put "10" and "0" and I get the same error with the difference that it's
TimeOnly
related 🤔so the default format is
"TestHour": "10:00:00"
"10:00:00"
should be workingtebeco#0205
REPL Result: Success
Result: Foo
Compile: 587.495ms | Execution: 74.442ms | React with ❌ to remove this embed.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Bar -> bar
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
tebeco#0205
REPL Result: Success
Result: Foo
Compile: 555.397ms | Execution: 73.660ms | React with ❌ to remove this embed.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ASP.NET Core adds some more configuration
apparently
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
It does make sense that it's ignored tho
tebeco#0205
REPL Result: Success
Result: Foo
Compile: 585.214ms | Execution: 79.647ms | React with ❌ to remove this embed.
Tvde1#0587
REPL Result: Success
Result: Foo
Compile: 587.900ms | Execution: 76.974ms | React with ❌ to remove this embed.
what are you guys doing pfffft
tebeco#0205
REPL Result: Success
Result: string
Compile: 647.548ms | Execution: 90.767ms | React with ❌ to remove this embed.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
AntonC#3545
REPL Result: Success
Result: int
Compile: 552.320ms | Execution: 76.993ms | React with ❌ to remove this embed.
@uselessxp
was eating, but I solved just in this moment, the problem was related to the sent body
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
swagger gave me automatically
"ticks: 0"
Then I replaced tons of value to the 0, but the problem i that I had to replace ALL removing "ticks:" also and the { } brackets
swagger*
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
if you're after optimal performance, don't use json
"Testhour": {
"ticks": 0
},
this was the generated bodythat's
TimeOnly
TimeSpan
then I solved using
"TestHour": 10:00:00,
quotes!
around the time
yeah with quotes, I just written it manually
now I'll make some additional tests, since I was asked to extend the model with lot of fields, then finally try to load data in a local DB table
the requests now it's ok, so I'll have to try this at the end
I lost like 2 hours searching solutions and I only had to remove "ticks" and brackets <:picard_facepalm:616692703685509130>
ops
if I'm not wrong, I think that the DB in which I should put the data "don't lik" strings for some columns
hm I think he don't like how do I pass it the objects