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

Serializing "unknown types" on JS release throws exception #473

Closed
jakdan99 opened this issue Apr 12, 2024 · 1 comment
Closed

Serializing "unknown types" on JS release throws exception #473

jakdan99 opened this issue Apr 12, 2024 · 1 comment
Labels
bug Something isn't working the way it was designed to.

Comments

@jakdan99
Copy link
Collaborator

Using the typescript declarations, encoding a StudyProtocolSnapshot which has an unknown type throws:
IllegalStateException: Could not find a matching field for "polymorphicDiscriminator" on the JavaScript runtime.

Repro steps:
#472

@Whathecode Whathecode added the bug Something isn't working the way it was designed to. label Apr 12, 2024
@Whathecode Whathecode changed the title Unknown type serialization throws exception Serializing "unknown types" on JS release throws exception Apr 12, 2024
@Whathecode
Copy link
Member

Thanks a lot for the repro! 🙏

Noteworthy: this works, and is tested, on the JS target platform.

I suspect the problem is related specifically to released sources, which get minified. Unknown polymorphism on the JS platform relies on accessing internals of kotlinx.serialization.

        // HACK: Modify kotlinx.serialization internals to ensure the encoder is not in polymorphic mode.
        //  Otherwise, `encoder.encodeJsonElement` encodes type information, but this is already represented in the wrapped unknown object.
        AccessInternals.setField( encoder, "polymorphicDiscriminator", null )

When the tests run with non-minified sources, however, this polymorphicDiscriminator field is renamed to something else.

This code was written quite a long time ago. We should check whether updates to kotlinx.serialization allow doing this without the HACK. But, if this is not possible, we will need to ensure the name is fixed by adding to the kotlinx.serialization facade.

Whathecode added a commit that referenced this issue Apr 13, 2024
Whathecode added a commit that referenced this issue Apr 13, 2024
Whathecode added a commit that referenced this issue Apr 13, 2024
Whathecode added a commit that referenced this issue Apr 14, 2024
Whathecode added a commit that referenced this issue Apr 14, 2024
Also had to update kotlinx serialization typescript wrapper due to new method call which was added in `UnknownPolymorphicSerializer` and caused the exported names to change.

Closes #473
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working the way it was designed to.
Projects
None yet
Development

No branches or pull requests

2 participants