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

Unable to serialize AdminStatusEnum after implemented doctrine Enum #345

Open
hiusing opened this issue Nov 14, 2024 · 3 comments
Open

Unable to serialize AdminStatusEnum after implemented doctrine Enum #345

hiusing opened this issue Nov 14, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@hiusing
Copy link

hiusing commented Nov 14, 2024

{"error":{"messages":["Encountered object of type \u0022Api\Admin\Enum\AdminStatusEnum\u0022 when serializing Mezzio\Hal\HalResource instance; unable to serialize"]}}

@alexmerlin
Copy link
Member

Hey @hiusing

Could you provide more details on how you encountered this issue?
Did it happen on calling a specific endpoint?
If not, please send a code snippet on how to reproduce the issue.

@alexmerlin alexmerlin self-assigned this Nov 14, 2024
@alexmerlin alexmerlin added the bug Something isn't working label Nov 14, 2024
@hiusing
Copy link
Author

hiusing commented Nov 15, 2024

Hi @alexmerlin

https://www.dotkernel.com/dotkernel/doctrine-enum-implementation-in-dotkernel/

The latest version of dotkernel api implement the Doctrine EnumType columns in the Admin and User. Mezzio\Hal\HalResource doesn't know how to serialize the AdminStatusEnumType.

When you composer serve and hit the endpoint at http://localhost:8080/admin to list all admin. You encounter the following error message at the brower:

  | {"error":{"messages":["Encountered object of type \u0022Api\Admin\Enum\AdminStatusEnum\u0022 when serializing Mezzio\Hal\HalResource instance; unable to serialize"]}}

@alexmerlin
Copy link
Member

@hiusing

Did you modify anything in your copy of Dotkernel API before running it and encountering this error?
Does this behaviour persist with other endpoints as well? i.e.: /admin/role, /users, /admin/my-account

Off-topic:

We strongly recommend using virtualhosts for running your applications.
They provide a low-effort solution for running applications without the need for manually starting them every time.
See our documentation on setting up WSL2 and creating virtualhosts in a WSL2 Linux distro if you're on WIndows.
If you are on a different operating system, you can find tutorials on the internet.


On-topic:

I just tested step-by-step using your method and could not reproduce the issue you are describing.


Recommendations:

  • make sure you are running the application in development mode so that config modifications are immediately available, without the need for clearing the cache first
  • make sure that the custom enum types are registered in your config/autoload/doctrine.global.php file
  • navigate to the root of your project and run the tests by executing the below command:
    (If present in the log directory, delete the current day's log file error-log-2024-11-XX.log else the tests might fail due to file permission issues)
composer test

If the tests succeed, it means that the serialization works.

Conclusion

Let us know your server specifications so we can narrow down possible causes of the issue you're describing:

  • operating system
  • PHP version
  • database type and client/server version
  • your Dotkernel API version (see the most recent release in your CHANGELOG.md file)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants