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

Form validation error response - field names not converted from camel case to underscore #587

Closed
lopsided opened this issue May 13, 2016 · 1 comment

Comments

@lopsided
Copy link

When I return my form errors like:

return View::create($form, 400);

The errors are returned like:

{"code":400,"message":"Validation Failed","errors":{"children":{"firstName":{"errors":["Your first name
 must not be empty."]},"lastName":{},"email":{}}}}

Where I was expecting firstName and lastName to come through as first_name and last_name.

All the rest of the serialization works fine (ie, returning objects, converting form posts etc). Just this.

My config (I'm using the FOSRestBundle):

fos_rest:
    param_fetcher_listener: force
    body_listener:
        array_normalizer: fos_rest.normalizer.camel_keys
    view:
        default_engine: json
        view_response_listener: force
        templating_formats:
            html: true
            twig: false
    routing_loader:
        default_format: json
    format_listener:
        rules:
            - { path: '^/', priorities: [ 'json' ], fallback_format: json, prefer_extension: false }
    serializer:
        serialize_null: true

jms_serializer:
    metadata:
        cache: ~
        directories:
            core:
                namespace_prefix: "MyProject\\Core"
                path: "@MyProjectApiBundle/Resources/config/serializer"

Apologies if this is a configuration problem.

I posted this here as the file that seems to be creating the response is JMS/Serializer/Handler/FormErrorHandler.php and I can't see if/where it is applying any naming strategy to the field names. (ie, line 145; $children[$child->getName()])

@goetas
Copy link
Collaborator

goetas commented Apr 25, 2017

Sorry for the terribly long feedback loop. Probably you have already solved your issue, but just to answer you, the FormErrorHandler does not follow the naming strategies, since is a custom handler for symfony forms

@goetas goetas closed this as completed Apr 25, 2017
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

2 participants