Unable to use properties of type "object" on model objects. Json serialization is seriously invalid.
The following code is used as a model.
When it is passed into the controller method:
14 Replies
I JUST want proper json to work. Arbitrary object goes in. Arbitrary object comes out. It shouldn't be so difficult! I'm frustrated on this. This has taken WAY more hours than it should have.
Wtf is valuekind
ValueKind is from System.Text.Json; there's something in the JsonDocument that acts as a raw string, as opposed to a number, or another Json object that requires further handling
other things it could be: https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonvaluekind?view=net-8.0
Is there a way to make this not so difficult?
Rather than save objects into the DB as json it is instead storing ValueKind 2.
Which is not at all what ti should be storing
I'm so sick of system.text.json right now.
if you want to store an
Object?
? ...not really
If you have something more specific than "literally anything that can be serialized into json" you can (somewhat) avoid dealing with the serializer directly, but if you need it to be that generic... you get to deal with itHow extremely frustrating.
I wasted 7 hours on this.
So how are we supposed to handle "just store your own json blob" use cases then? This is a huge miss.
@Tom (Taylor) can you show what the JSON being submitted to the endpoint looks like?
@jcotton42
is
data
always going to be that shape (that is, always a string list)?
or can it be any shape?Any shape. It's literally an endpoint for arbitrary json data storage. So many posts online say "why don't you just account for the docs you know will exist?" drives me bonkers...
make
Data
a JsonElement
instead of Object
(which is what it's already using anyhow afaict)
also, avoid naming your own type
JsonDocument
if reasonably possible
how are you persisting this to the database?{"Operation is not valid due to the current state of the object."}
I;'ll join chat hang on
MYSQL thoughg
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.