Skip to content
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

Cannot serialize/deserialize object without parameterless constructor #40

Closed
mongeon opened this issue Jan 13, 2021 · 3 comments · Fixed by dotnet/efcore#30588
Closed
Assignees
Labels
enhancement New feature or request fixed
Milestone

Comments

@mongeon
Copy link

mongeon commented Jan 13, 2021

I've started using the HierarchyId for a Blazor project I've started and it's was failing as it's use Json for serialize/deserialize object and HierarchyId doesn't have one. I've create a simple converter to perform the task. I'm not sure if this should belong in this repository or not.

using Microsoft.EntityFrameworkCore;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ANamespace
{
    public class HierarchyIdConverter : JsonConverter<HierarchyId>
    {
        public override HierarchyId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            return HierarchyId.Parse(reader.GetString());
        }

        public override void Write(Utf8JsonWriter writer, HierarchyId value, JsonSerializerOptions options)
        {
            writer.WriteStringValue(value.ToString());
        }
    }
}
@bricelam
Copy link
Member

bricelam commented May 3, 2021

Are there any BCL annotations we can add to HierarchyId to make it more JSON-friendly?

@bricelam bricelam added the enhancement New feature or request label Oct 11, 2022
@bricelam bricelam added this to the Backlog milestone Oct 11, 2022
@bricelam
Copy link
Member

If anyone would still like to see out-of-the-box support for serializing to JSON, please submit an issue on dotnet/efcore.

@bricelam bricelam closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2023
@bricelam bricelam removed this from the Backlog milestone Feb 17, 2023
bricelam added a commit to bricelam/efcore that referenced this issue Mar 27, 2023
Changes:
- Make HierarchyId compatible with System.Text.Json (resolves efcore/EFCore.SqlServer.HierarchyId#40)
- Add HierarchyId constructors
- Add overloads and clarify docs for GetDescendant
- Improve interop with SqlHierarchyId
- Translate calls on constants (fixes dotnet#30307)
- Don't go through SqlBytes (resolves dotnet#30305)

Part of dotnet#30306
@bricelam
Copy link
Member

We decided to add a built-in JSON converter to EF8

@bricelam bricelam reopened this Mar 27, 2023
@bricelam bricelam added the fixed label Mar 27, 2023
@bricelam bricelam self-assigned this Mar 27, 2023
@bricelam bricelam added this to the 8.0.0 milestone Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed
Development

Successfully merging a pull request may close this issue.

2 participants