Skip to content

v12.0.0 Support polymorphism in response deserialization

Choose a tag to compare

@github-actions github-actions released this 22 Oct 06:46
· 107 commits to master since this release
Immutable release. Only release title and notes can be modified.
b4b857c

What's Changed

  • Support polymorphism in response deserialization by @eucyt in #746

This change introduces polymorphism support in API responses.
⚠️ This includes breaking changes.

As-Is

Polymorphic types in responses were not handled correctly.
As a result, all responses were deserialized into the base class, making it impossible to access subclass-specific properties.

$api = new MessagingApiApi($client);
$richMenuListResponse = $api->getRichMenuList();

// Even if type=postback, it becomes an instance of Action, not PostbackAction
$action = $richMenuListResponse->getRichmenus()[0]->getAreas()[0]->getAction();
// Error: Call to undefined method LINE\Clients\MessagingApi\Model\Action::getData()
$data = $action->getData();
// or simply null
$data = $action["data"];

To-Be

Polymorphic types in responses are now properly supported.
Each response is deserialized into the correct subclass, allowing subclass properties to be accessed safely.

This change applies to all API responses, not just this specific endpoint.
If your existing code depends on the base class types, you will need to update it accordingly.
You can now directly access subclass-specific properties when polymorphism is involved.

When the discriminator is unknown, it is deserialized into the parent class, and no error occurs.

$api = new MessagingApiApi($client);
$richMenuListResponse = $api->getRichMenuList();

// If type=postback, it will now become an instance of PostbackAction
$action = $richMenuListResponse->getRichmenus()[0]->getAreas()[0]->getAction();
// You can now access subclass-specific properties
$data = $action->getData();
$data = $action["data"];

Full Changelog: v11.4.0...v12.0.0


This release is prepared by @eucyt