Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Issues with DocumentJsonSerializerOptions serialization and derived types #17091

Closed
giannik opened this issue Nov 28, 2024 · 0 comments
Closed
Labels

Comments

@giannik
Copy link
Contributor

giannik commented Nov 28, 2024

I'm having some issues lately with Serialization of derived C# types using DocumentJsonSerializerOptions .

In Orchard Core you can define the derived types for serialization from this serviceL

  services.AddJsonDerivedTypeInfo<derived, base>();

But I noticed lately (this was not happening about a month ago )that when you try to serialize the derived type that has been defined from the startup services that when you serialize it doesn't contain the type info metadata to later on deserialize it back to the derived type.
As an example the following code serializes the ContentDeploymentStep without the type info metadata :

public class TestController : Controller
  private readonly JsonSerializerOptions _jsonSerializerOptions;
 public TestController (
        IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions
  )
{
   _jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
}
  public Task<IActionResult> Test()
    {
         var TestDerivedType= new ContentDeploymentStep(){Name = "Test"};
         var serialized= JsonSerializer.Serialize(TestDerivedType, _jsonSerializerOptions); //serialized string does not contain the type information 
           metadata
    }

     
  //later on when deserializing back it does not convert to the derived class but to base class

Can someone please confirm if it happens on their side?

@OrchardCMS OrchardCMS locked and limited conversation to collaborators Nov 28, 2024
@Piedone Piedone converted this issue into discussion #17094 Nov 28, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

1 participant