{"action":"created","issue":{"url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/310","labels_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/310/labels{/name}","comments_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/310/comments","events_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/310/events","html_url":"https://github.com/marshmallow-code/marshmallow/issues/310","id":113640892,"number":310,"title":"Opposite functionality of 'load_from' needed. Perhaps 'dump_to'?","user":{"login":"ShayanArmanPercolate","id":14059582,"avatar_url":"https://avatars.githubusercontent.com/u/14059582?v=3","gravatar_id":"","url":"https://api.github.com/users/ShayanArmanPercolate","html_url":"https://github.com/ShayanArmanPercolate","followers_url":"https://api.github.com/users/ShayanArmanPercolate/followers","following_url":"https://api.github.com/users/ShayanArmanPercolate/following{/other_user}","gists_url":"https://api.github.com/users/ShayanArmanPercolate/gists{/gist_id}","starred_url":"https://api.github.com/users/ShayanArmanPercolate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShayanArmanPercolate/subscriptions","organizations_url":"https://api.github.com/users/ShayanArmanPercolate/orgs","repos_url":"https://api.github.com/users/ShayanArmanPercolate/repos","events_url":"https://api.github.com/users/ShayanArmanPercolate/events{/privacy}","received_events_url":"https://api.github.com/users/ShayanArmanPercolate/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-10-27T17:42:09Z","updated_at":"2015-10-28T21:54:40Z","closed_at":null,"body":"Currently, there is an attribute on the Field class called load_from. This is useful when a schema pythonic style fields, but the service could accept CamelCase field names.\r\n\r\nex.\r\nclass JobSchema(Schema):\r\n    pipeline_id = fields.Str(load_from='PipelineId', load_only=True, required=True)\r\n\r\nThis is a great solution for deserialization. However, when serializing, it would be great to change the key from pipeline_id back to PipelineId. My current solution is to have a dump_only field that uses the attribute parameter to take the value of pipeline_id:\r\n\r\nclass JobSchema(Schema):\r\n    pipeline_id = fields.Str(load_from='PipelineId', load_only=True, required=True)\r\n    PipelineId = fields.Str(dump_only=True, attribute='pipeline_id')\r\n\r\nIs there a better way to do this? \r\n\r\nThanks a lot!\r\nShayan\r\n@sloria "},"comment":{"url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/comments/152006354","html_url":"https://github.com/marshmallow-code/marshmallow/issues/310#issuecomment-152006354","issue_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/310","id":152006354,"user":{"login":"franciscod","id":726447,"avatar_url":"https://avatars.githubusercontent.com/u/726447?v=3","gravatar_id":"","url":"https://api.github.com/users/franciscod","html_url":"https://github.com/franciscod","followers_url":"https://api.github.com/users/franciscod/followers","following_url":"https://api.github.com/users/franciscod/following{/other_user}","gists_url":"https://api.github.com/users/franciscod/gists{/gist_id}","starred_url":"https://api.github.com/users/franciscod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/franciscod/subscriptions","organizations_url":"https://api.github.com/users/franciscod/orgs","repos_url":"https://api.github.com/users/franciscod/repos","events_url":"https://api.github.com/users/franciscod/events{/privacy}","received_events_url":"https://api.github.com/users/franciscod/received_events","type":"User","site_admin":false},"created_at":"2015-10-28T21:54:40Z","updated_at":"2015-10-28T21:54:40Z","body":"Following your examples:\r\n\r\n```python\r\nfrom marshmallow import Schema, fields\r\n\r\nschemas = []\r\n\r\nclass JobSchemaActualSolution(Schema):\r\n    pipeline_id = fields.Str(load_from='PipelineId', load_only=True, required=True)\r\n    PipelineId = fields.Str(dump_only=True, attribute='pipeline_id')\r\n\r\nschemas.append(JobSchemaActualSolution)\r\n\r\n\r\nclass JobSchemaDumpTo(Schema):\r\n    pipeline_id = fields.Str(load_from='PipelineId', load_only=True, required=True)\r\n    PipelineId = fields.Str(dump_only=True, attribute='pipeline_id')\r\n\r\nschemas.append(JobSchemaDumpTo)\r\n\r\n\r\nclass JobSchemaLoadFromDumpTo(Schema):\r\n    pipeline_id = fields.Str(load_from='PipelineId', dump_to='PipelineId', required=True)\r\n\r\nschemas.append(JobSchemaLoadFromDumpTo)\r\n\r\n\r\nclass JobSchemaLoadFromAttribute(Schema):\r\n    pipeline_id = fields.Str(load_from='PipelineId', attribute='PipelineId', required=True)\r\n\r\nschemas.append(JobSchemaLoadFromAttribute)\r\n\r\n\r\n\r\ndata = {'PipelineId': 'abc123'}\r\n\r\nfor schema in schemas:\r\n    s = schema()\r\n    l = s.load(data)\r\n    print(l)\r\n    res, errors = l\r\n\r\n    d = s.dump(res)\r\n    print(d)\r\n    res, errors = d\r\n\r\n    print(res)\r\n    print(data)\r\n    print('--')\r\n\r\n```\r\n\r\n```\r\nUnmarshalResult(data={'pipeline_id': 'abc123'}, errors={})\r\nMarshalResult(data={'PipelineId': 'abc123'}, errors={})\r\n{'PipelineId': 'abc123'}\r\n{'PipelineId': 'abc123'}\r\n--\r\nUnmarshalResult(data={'pipeline_id': 'abc123'}, errors={})\r\nMarshalResult(data={'PipelineId': 'abc123'}, errors={})\r\n{'PipelineId': 'abc123'}\r\n{'PipelineId': 'abc123'}\r\n--\r\nUnmarshalResult(data={'pipeline_id': 'abc123'}, errors={})\r\nMarshalResult(data={'PipelineId': 'abc123'}, errors={})\r\n{'PipelineId': 'abc123'}\r\n{'PipelineId': 'abc123'}\r\n--\r\nUnmarshalResult(data={'PipelineId': 'abc123'}, errors={})\r\nMarshalResult(data={'pipeline_id': 'abc123'}, errors={})\r\n{'pipeline_id': 'abc123'}\r\n{'PipelineId': 'abc123'}\r\n---\r\n```\r\n\r\nI thought the 4th schema would have the same output as the others... I definitely don't get how `attribute` works :)"}}