-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Similar to #131, but for deserialization.
Given the following class structure:
public class Person : ApiResource
{
public Person()
{
Attribute("Name");
}
public Name Name { get; set; }
}
public class Name
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
...the following JSON (e.g. in a POST
request):
{
"data": {
"attributes": {
"name": {
"first-name": "John",
"last-name": "Doe"
}
}
}
}
...will result in a Person
class such that person.Name.FirstName == null
and person.Name.LastName == null
.
However, if the nested attributes are changed to UpperCamelCase (e.g. FirstName
and LastName
), then the result is correct (e.g. person.Name.FirstName == "John"
, person.Name.LastName == "Doe"
). And when serializing (e.g. in a response), the result has the expected kebab-case (because of #131).
I know many examples of nested objects like this can probably be refactored as relationships, etc., but as discussed in #131 it's sometimes useful to use "value objects" for grouping of closely-related attributes.
Additionally, if the default behavior for serialization is to handle kebab-casing all the way down, then it seems reasonable that the same should be true for deserialization for consistency and request/response symmetry.
From poking around the code a bit, it seems like the ResourceDeserializer
would have to be changed to recursively call ToFlatStructure()
for non-primitive attribute values (similar to what it does for relationships).