You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
S.T.J.JsonSerializer does not serialize value tuples #29045
You will get a string representing an empty object {}. I think the right behavior is to have { "Item1": 1, "Item2": 2 } and I expect it should also work for deserialization.
Great @YohDeadfall. I sent you collaborator invite to CoreFX repo. We recommend to swtich the repo to Not Watching, otherwise you will receive 500+ notifications per day (may be a bit overwhelming). The Not Watching setting will send you notifications for issues where you are mentioned, you are assigned or where you explicitly subscribed.
Once you accept the collaborator invite, please ping me, I will assign the issue to you then (GH limitation, assigning to myself for now).
It does work for some of the primitive structures such as DateTime, however it does not work for DateTimeOffset. They could be different issues to track.
@mazhou-msftDateTimeOffset is a different kind of structure which should be serialized as a single value. Such kind of types should be handled by value converters. I'm talking about value types which have serializable public properties and fields.
@karelz Take a look at the expected output. There are Item1 and Item2 properties which corresponds to fields of ValueTuple<,>. So the issue isn't about serialization of value tuples with their field aliases which are a and b in the example.
For the expected result, I would say a and b may be more natural, but it makes things harder (for those runtime TupleElementName checks etc.) back one step, Item1 and Item2 are still acceptable results as they are identitical to what Json.NET returns for value tuples.
For the second issue regarding the DateTimeOffset, I expect at least get a JSON representing all public properties, if the value onverter is not ready yet; however I am receiving TargetInvocationException which seems a bug to me, we should fix it somewhere too.
Is this issue about providing struct support (i.e. value types), or is it about supporting ValueTuples specifically (which just happen to be a value type)?
I tried this out earlier today using 3.0.0-preview6-27728-02 and things are essentially the same as the original reported issue. Could we consider throwing if the serializer encounters a ValueTuple for 3.0 if there isn't enough runway to support the feature in this release? The experience is a bit frustrating since it seems like serialization succeeded, but all you have is empty objects.
ValueTuple has fields, not properties, and the current implementation doesn't support them. There is #876 to track progress (am working on it and will try to open a PR on this weekend).
Activity
YohDeadfall commentedon Mar 29, 2019
@ahsonkhan @karelz I would like to take it.
karelz commentedon Mar 29, 2019
Great @YohDeadfall. I sent you collaborator invite to CoreFX repo. We recommend to swtich the repo to Not Watching, otherwise you will receive 500+ notifications per day (may be a bit overwhelming). The Not Watching setting will send you notifications for issues where you are mentioned, you are assigned or where you explicitly subscribed.
Once you accept the collaborator invite, please ping me, I will assign the issue to you then (GH limitation, assigning to myself for now).
YohDeadfall commentedon Mar 29, 2019
By the way, can you replace "value tuples" in the title by "structures"?
karelz commentedon Mar 29, 2019
Well, the original issue was for "value tuples". Do you mean it could / should be generalized? If yes, I let @ahsonkhan comment on that.
mazhou-msft commentedon Mar 29, 2019
It does work for some of the primitive structures such as
DateTime, however it does not work forDateTimeOffset. They could be different issues to track.YohDeadfall commentedon Mar 29, 2019
@mazhou-msft
DateTimeOffsetis a different kind of structure which should be serialized as a single value. Such kind of types should be handled by value converters. I'm talking about value types which have serializable public properties and fields.@karelz Take a look at the expected output. There are
Item1andItem2properties which corresponds to fields ofValueTuple<,>. So the issue isn't about serialization of value tuples with their field aliases which areaandbin the example.mazhou-msft commentedon Mar 29, 2019
Make sense.
For the expected result, I would say
aandbmay be more natural, but it makes things harder (for those runtimeTupleElementNamechecks etc.) back one step,Item1andItem2are still acceptable results as they are identitical to what Json.NET returns for value tuples.For the second issue regarding the
DateTimeOffset, I expect at least get a JSON representing all public properties, if the value onverter is not ready yet; however I am receiving TargetInvocationException which seems a bug to me, we should fix it somewhere too.steveharter commentedon Mar 29, 2019
DateTimeOffsetsupport was just added.There is no converter yet for
ValueTuple, so using this issue to track that.mazhou-msft commentedon Mar 29, 2019
Thanks for the info, sounds good.
ahsonkhan commentedon Apr 1, 2019
Is this issue about providing struct support (i.e. value types), or is it about supporting ValueTuples specifically (which just happen to be a value type)?
ahsonkhan commentedon May 20, 2019
Re-opening since it isn't fully fixed yet.
buyaa-n commentedon May 27, 2019
Adding a test case:
pranavkm commentedon May 28, 2019
I tried this out earlier today using
3.0.0-preview6-27728-02and things are essentially the same as the original reported issue. Could we consider throwing if the serializer encounters aValueTuplefor 3.0 if there isn't enough runway to support the feature in this release? The experience is a bit frustrating since it seems like serialization succeeded, but all you have is empty objects.YohDeadfall commentedon May 29, 2019
ValueTuplehas fields, not properties, and the current implementation doesn't support them. There is #876 to track progress (am working on it and will try to open a PR on this weekend).karelz commentedon May 29, 2019
Duplicate of #876
ahsonkhan commentedon Jan 9, 2020
I mention a workaround for
ValueTuples(up to 3) based on custom converters if folks need it.#1519 (comment)