Coder Social home page Coder Social logo

Keep fields order about marshmallow HOT 4 CLOSED

zerodivisi0n avatar zerodivisi0n commented on August 19, 2024
Keep fields order

from marshmallow.

Comments (4)

sloria avatar sloria commented on August 19, 2024

You are correct; using the fields or additional class Meta options does not preserve order in the final output.

Will push a patch to this soon.

Thanks for reporting!

from marshmallow.

zerodivisi0n avatar zerodivisi0n commented on August 19, 2024

It's great! Thank you for this library!

from marshmallow.

zerodivisi0n avatar zerodivisi0n commented on August 19, 2024

Ok, just checked it.
But it does not work with declaring serializer like so:

class PersonSerializer(Serializer):
    id = fields.String()
    created_at = fields.DateTime()
    name = fields.String()
    phone = fields.String()
    email = fields.String()

The result looks like this:

{"name": "Guido van Rossum", "created_at": "2014-08-20T23:17:31.705290+00:00", "id": "125", "phone": "", "email": "[email protected]"}

I did not have much time to sort out what is the reason, but I think the problem in method get_declared_fields:

>>> s = PersonSerializer()
>>> s.declared_fields
OrderedDict([('name', <String Field>), ('created_at', <DateTime Field>), ('id', <String Field>), ('phone', <String Field>), ('email', <String Field>)])

from marshmallow.

sloria avatar sloria commented on August 19, 2024

Thanks for catching that. Ordering of declared fields has been fixed as well.

from marshmallow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.