Skip to content

stdClass Serialization Does Not Use Property Naming Strategy #1499

@BrandonKahre

Description

@BrandonKahre
Q A
Bug report? no
Feature request? no
BC Break report? maybe?
RFC? no

I am upgrading an old application that was using jms/serializer 1.14.1. I have upgraded it to 3.24.0 and am seeing different behavior that wasn't reported as a BC and I'm not finding any information about how to get back to the old ways.

The issue revolves around serializing \stdClass objects. Previous behavior would be to apply the property naming strategy, which by default meant converting camel case to snake case. On the newer version, however, \stdClass does not appear to use the property naming strategy, even if defined explicitly.

What am I missing?

Steps required to reproduce the problem

        $data = (object) [
            "success" => true,
            "financingPartnerName" => "MoneyMan",
            "dealerFee" => 6.5,
        ];
        $serializer = \JMS\Serializer\SerializerBuilder::create()
            ->setPropertyNamingStrategy(new \JMS\Serializer\Naming\CamelCaseNamingStrategy())
            ->addDefaultHandlers()
            ->build();
        $json = $serializer->serialize($data, 'json');
        dump($json);

Expected Result

{
    "success": true,
    "financing_partner_name": "MoneyMan",
    "dealer_fee": 6.5
}

Actual Result

{
    "success": true,
    "financingPartnerName": "MoneyMan",
    "dealerFee": 6.5
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions