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

Type error in UnionHandler #1566

Open
dmaicher opened this issue Nov 6, 2024 · 5 comments
Open

Type error in UnionHandler #1566

dmaicher opened this issue Nov 6, 2024 · 5 comments

Comments

@dmaicher
Copy link

dmaicher commented Nov 6, 2024

Q A
Bug report? yes
Feature request? yeso
BC Break report? yes
RFC? no

Steps required to reproduce the problem

jms/serializer        3.31.1 Library for (de-)serializing data of any complexity; supports XML, and JSON.
jms/serializer-bundle 5.5.1  Allows you to easily serialize, and deserialize data of any complexity
$serializer = SerializerBuilder::create()->build();
$serializer->serialize(new class() {
    public array|int $foo = [1, 2, 3];
}, 'json');

Expected Result

  • Should work fine

Actual Result

TypeError:
get_class(): Argument #1 ($object) must be of type object, array given

  at vendor/jms/serializer/src/Handler/UnionHandler.php:56
@scyzoryck
Copy link
Collaborator

It looks like arrays are not supported in current implementation at all. I will take a look at it. Looks like @simPod already started some work around that.
#1552

@mermshaus
Copy link

mermshaus commented Nov 11, 2024

I can confirm this issue. Unfortunately, it breaks existing code. For the time being, we had to pin jms/serializer to v3.30.0 because of this. It might be a good idea to release a new version reverting these changes until the feature supports arrays. (Or, as I see the issue with that, to specify a workaround for disabling the new feature.)

#1552 isn’t working on this, I think. The MR is about “unions” (not really) in arrays, not arrays in unions.

@goetas
Copy link
Collaborator

goetas commented Nov 12, 2024

Unfortunately, it breaks existing code

@scyzoryck would it make sense to revert the union types thing that is causing this error?

from my understanding, #1546 is the guilty one, right?

@scyzoryck
Copy link
Collaborator

We also I think have 2 MRs on top of #1546 so it might need some additional reverts. As an example: #1563
Current issues with Union Types:

  • High prio: Support for true and false types. MR: Support value types in serialization #1569 - we need to add some
  • High prio: Support for array type - I believe I can finish the basic support (fix the issue from this issue), feat: support unions in arrays #1552 may add complex types later.
  • Medium/Low prio: It looks like there might be some issues with DepthExclusionStrategy for Union types, but I guess it was not working in the past at all.

Soo, personally I would go with fixing the issues, and going with the fix release this week with support for missing types.

@goetas
Copy link
Collaborator

goetas commented Nov 14, 2024

Soo, personally I would go with fixing the issues, and going with the fix release this week with support for missing types.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants