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 Serialize return weird result #46869
Comments
{
"$id": "1",
"b": 1,
"c": {
"$id": "2",
"$values": [
{
"$id": "3",
"d": 4,
"g": "test"
}
]
},
"c_copy": {
"$ref": "2"
},
"my_a": {
"$ref": "1"
}
} Note that since you need |
We rolled back to Newtonsoft. Thank you |
You have your own logic. But we cannot use that. |
.... what are you talking about, it's perfectly valid JSON? What's not "normal" is the use of the various id links. You'd have to tell Java/Python to handle them (and I would bet there are already libraries to do so). That said, usually you don't have duplicate objects/circular references, so you just serialize everything by value. |
Why didn't you give me ReferenceHandler.Ignore option? |
That's not what your issue is currently filed as (referencing the way lists are serialized vs how cyclical graphs are handled). Now that it's more obvious what you actually want, you want to file an API request. Note that the equivalent behavior in Newtonsoft is handled via a completely separate option,
Probably because this might be the first time anybody has asked for this behavior. |
"That's not what your issue is currently filed as" "this might be the first time anybody has asked for this behavior" |
That's #40099, which has already been approved and should be included in .Net 6.0. |
Please have a look at the following code:
`using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace ConsoleApp7
{
public class a
{
public int b { get; set; }
public List<e> c { get; set; }
public a my_a { get; set; }
}
public class e
{
public int d { get; set; }
public string g { get; set; }
}
}
`
The output:
{ "$id": "1", "b": 1, "c": { "$id": "2", "$values": [ { "$id": "3", "d": 4, "g": "test" } ] }, "my_a": { "$ref": "1" } }
Look at the c array in the output string. What the hell is that? Array became object?
Please, this is disgusting
Please provide ReferenceHandler.Ignore
ReferenceHandler.Preserve is stupid
The text was updated successfully, but these errors were encountered: