You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are cases where an application may need control over the output label where it might differ from the attribute name.
The case I am working on is a JSON-LD serializer, where labels can start with the @ prefix: @id, @type, etc. This is not a valid attribute name in Python, but it should be reflected in the serialized output.
I've tried to get around this with custom subclasses, but adherence to the attribute name as output label is fairly deep in the functioning of the serializer.
So what I propose is to add an (optional) label to serializer fields, label, that would get carried along in the _compile_field_to_tuple tuple. If label is not None, the _serializer method uses it as the key in the output instead of name.
If this sounds like something you would find useful, I could put together a pull request and send it upstream.
The text was updated successfully, but these errors were encountered:
I think this is a great idea, feel free to submit a pull request. I believe the only use of "name" in the compiled_fields is to set the key value in the returned dict, so you might be able to just replace name with label if its set.
This commit adds an optional parameter, label, to a Field. When serialized, the serializer will use the label if it is defined, or it will default to using the attribute name as before.
This commit includes two new unit tests for this functionality.
Fixesclarkduvall#14
There are cases where an application may need control over the output label where it might differ from the attribute name.
The case I am working on is a JSON-LD serializer, where labels can start with the
@
prefix:@id
,@type
, etc. This is not a valid attribute name in Python, but it should be reflected in the serialized output.I've tried to get around this with custom subclasses, but adherence to the attribute name as output label is fairly deep in the functioning of the serializer.
So what I propose is to add an (optional) label to serializer fields,
label
, that would get carried along in the_compile_field_to_tuple
tuple. Iflabel
is notNone
, the_serializer
method uses it as the key in the output instead ofname
.If this sounds like something you would find useful, I could put together a pull request and send it upstream.
The text was updated successfully, but these errors were encountered: