Skip to content

Conversation

ioigoume
Copy link

@ioigoume ioigoume commented Sep 8, 2025

JsonMapper failed to map JSON scalar values into PHP 8.1+ backed enum-typed properties and incorrectly treated them as objects. This caused errors like:

JsonMapper_Exception: JSON property "exampleEnumMode" must be an object, string given.

What changed

  • Added an enum handling condition branch that:
    • Detects enum-typed targets via enum_exists($type).
    • Converts the incoming JSON scalar using type::tryFrom(jvalue).
    • Throws a JsonMapper_Exception with a clear message if the value is not part of the enum.
    • Sets the property with the resulting enum case.

Before

  • Mapping a JSON string (e.g., "optional") into an enum-typed property resulted in an error insisting on an object type.

After

  • Mapping a JSON string that matches a backed enum value (e.g., "optional") correctly produces the corresponding enum case (e.g., ExampleEnumMode::OPTIONAL).
  • Invalid values now yield a precise error: Enum value "" does not belong to enumerator class.

@cweiske
Copy link
Owner

cweiske commented Sep 8, 2025

This looks like AI generated code. I don't accept code generated by an AI.

@ioigoume
Copy link
Author

ioigoume commented Sep 8, 2025

This looks like AI generated code. I don't accept code generated by an AI.

@cweiske

What part of the actual code is AI generated? I am getting this issue:

JsonMapper_Exception: JSON property "encryptAssertionsMode" must be an object, string given

and i tracked down the problem to the JsonMapper.php::299. I fixed and tested that i do not get the error report in my testing environment. Then i added a couple of tests that support this. Then i opened the PR. Simple as that.

@ioigoume ioigoume force-pushed the Map_enum_class_issue branch from 2c3c878 to b850b5c Compare September 8, 2025 13:33
@cweiske
Copy link
Owner

cweiske commented Sep 8, 2025

The issue description looks totally generated.

@ioigoume
Copy link
Author

ioigoume commented Sep 8, 2025

The issue description looks totally generated.

@cweiske yes it is. This does not make the code neither AI generated, nor untested/unverified.
I came across an issue, while using the library. I came up with a solution and i proposed that solution. This entails that i had to run and extend the tests, run the code sniffer and fix any issues, etc. At the end i used the convenience of an AI generator to create a better description/comment of what i found. Is that a bad thing?

@ioigoume
Copy link
Author

ioigoume commented Sep 8, 2025

Related Issue #247

@ioigoume ioigoume force-pushed the Map_enum_class_issue branch from d403a67 to b850b5c Compare September 8, 2025 16:33
@SvenRtbg
Copy link
Contributor

SvenRtbg commented Sep 8, 2025

Related Issue #247

Please follow up on this issue's discussion and illustrate how you'd go forward when a setting is stating that no objects are being generated when scalar values are encountered. Also consider the mentioned issue with DateTime*.

@ioigoume ioigoume force-pushed the Map_enum_class_issue branch from b850b5c to 9023cf7 Compare September 9, 2025 06:35
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

Successfully merging this pull request may close these issues.

3 participants