dataclasses-json icon indicating copy to clipboard operation
dataclasses-json copied to clipboard

Improved support for mixed casing

Open djmattyg007 opened this issue 3 years ago • 2 comments

When using camelCase letter casing, MyDataClass.from_dict() still supports the original snake_case letter casing. However, MyDataClass.schema().load() doesn't. This isn't a big deal - just use from_dict(). However, from_dict() doesn't support many=True. From what I understand, calling from_dict() repeatedly is slower than once with a list and many=True.

Is this magic support for mixed casing by from_dict() intentional? If not, should it be removed? If it is, could it also support many=True?

djmattyg007 avatar Mar 03 '21 12:03 djmattyg007

I'm running into the same issue. I'm trying to use the marshmallow schema that gets generated by dataclass_json to validate user input and catch a marshmallow ValidationError when the request body doesn't match the schema, but it seems that this method doesn't convert camelCase to snake_case (even though my dataclass was defined with letter_case=LetterCase.CAMEL)

ewolz3 avatar Apr 13 '21 16:04 ewolz3

Hi @djmattyg007, thanks for reporting this

is this magic support for mixed casing by from_dict() intentional?

your suspicion is right that this wasn't intentional, it should be an error to successfully from_dict on a snake_case field when it expects camelCase

@ewolz3

but it seems that this method doesn't convert camelCase to snake_case (even though my dataclass was defined with letter_case=LetterCase.CAMEL)

this sounds like a different issue -- but perhaps I'm missing something? are you using .schema().load(...) on a JSON blob with camelCase?

lidatong avatar Apr 26 '21 13:04 lidatong