Coder Social home page Coder Social logo

Comments (6)

jone avatar jone commented on July 18, 2024

Should this maybe be a two-way solution so that we can prepare data for updating / creating?

from plone.restapi.

tisto avatar tisto commented on July 18, 2024

Please note that the schema serialization was just a proof-of-concept. That was never meant to be the final code.

Your questions:

  1. Not that I would know.
  2. Could go into plone.restapi first, could be refactored into a separate package as well.
  3. Looks ok to me. Adapters always work. ;)

from plone.restapi.

jone avatar jone commented on July 18, 2024

Ok, thanks. I'll make a PR 😉

from plone.restapi.

lukasgraf avatar lukasgraf commented on July 18, 2024

Looks good to me :)

Is there already some serialization mechanism which produces JSON-compatible output (!) for dexterity?

I wouldn't know of one that does exactly this, but:

  • plone.supermodel provides XML import and export for schema interfaces based on zope.schema fields
  • plone.rfc822 does marshalling of content objects described by zope.schema fields from and to RFC (2)822 messages (E-Mail / HTTP-Messages).

So even though they do something different, it still could be worth a look for some tricky cases, maybe we can pick up some odd bits and pieces from these packages.

from plone.restapi.

lukasgraf avatar lukasgraf commented on July 18, 2024

I think the IFieldSerializer adapter and your choice of discriminators is the way to go, but at some later stage we might need another layer of abstraction:

We'll have use cases where we'll want to serialize objects that aren't Plone content types (think SQL backed content for example). When using SQLAlchemy the Column objects could play a similar role to fields, in that the describe the data type, but I could imagine cases where you don't even have a field to adapt - you just know you're dealing with a datetime, and you want to be able to re-use the conversion to a JSON-compatible ISO format instead of writing it yourself.

So maybe at some later stage, we'd need some concept like plain Converters, where a DateTimeFieldSerializer would delegate to a DateTimeConverter instead of doing the conversion itself.

from plone.restapi.

buchi avatar buchi commented on July 18, 2024

I've got two suggestions of cosmetic nature:

  • IFieldSerializer should adapt the field first as it is the main thing that is adapted:
    def __init__(self, field, context, request)
  • Do serialization in the __call__() method instead of a serialize()method. This reduces verbosity in code serializer.serialize() vs. serializer()

I've started implementing deserialization in #41 following this approach.

from plone.restapi.

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.