Skip to content

Unable to serialize AdminStatusEnum after implemented doctrine Enum  #345

Closed

Description

@storexstore

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

Activity

  1. alexmerlin commented on Nov 14, 2024

    @alexmerlin
    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.

  2. self-assigned this
    on Nov 14, 2024
  3. storexstore commented on Nov 15, 2024

    @storexstore
    Author

    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"]}}

  4. alexmerlin commented on Nov 15, 2024

    @alexmerlin
    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)
  5. locked and limited conversation to collaborators on May 5, 2025
  6. converted this issue into a discussion #420 on May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingquestionFurther information is requested

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions