Closed jviney closed 8 years ago
This is good point. We could always make those variables public. I think it might be better however to implement some kind of global FieldNameSerialiser that takes care of converting names to their serialised names. That way you could configure this on the Spine instance instead of having to subclass.
Agree with @wvteijlingen. Inheritance is not the solution, but composition.
+1 for making name
and serializedName
public
I'm experimenting with a way to globally configure key formatting. You can find this in the key-formatter branch.
Instead of having to specify the serialised name for every attribute, you can now use a UnderscoredKeyFormatter
and let Spine format al your fields for you:
spine.keyFormatter = UnderscoredKeyFormatter()
By default it uses the DasherizedKeyFormatter
because dasherized keys are recommended by the JSON:API spec. The serialised name is still there if you need to configure a custom name for a field. The serialised name does not have to be formatted, it will still go through the keyFormatter.
If you happen to check it out, please let me know whether this works for your use case :).
Nice work. The KeyFormatter implementations need some public initialisers though.
Done!
:clap: :clap: :clap: :clap:
Hi,
Thanks for the great work on Spine - it's fantastic :+1: .
The API I'm working with always uses underscored strings for serialization. Rather than specifying the serialized name every time with
Attribute().serializedAs("underscored_name_here")
I'd instead like to override or subclassAttribute
to make this the default.This seems tricky currently because none of the properties of the
Field
class are public, and hence can't be overridden or accessed from a subclass inside a my project.Could the
name
andserializedName
properties be made public? I'm happy to provide a patch. I also tried to provide a different implementation offieldsFromDictionary
, but a similar problem exists because thename
field is not accessible. Or perhaps there is a better way to do this?I'm using the swift-2.0 branch.
Cheers.