Coder Social home page Coder Social logo

Comments (4)

wenderjean avatar wenderjean commented on June 18, 2024 1

In my opinion, the static method toJSON seems more a kind of callback that should actually be named as afterSerialize or something like that, but, we can fall in a lot of problems dealing with this approach since it doesn't matter the feature you're gonna be dealing with the serialization will be always compromised to the behavior declared in afterSerialize.

The second point is, it will assume that the structure model should do more than it is proposed to do, for example, to harbor unnecessary business serialization logic.

I agree with @talyssonoc that complex serialization should live in a serializer layer and this feature will just add complexity to solve a problem more related to architectural design.

from structure.

talyssonoc avatar talyssonoc commented on June 18, 2024

Hello, @loweoj, sorry for the delay on answering this issue. I really like the idea, but I'm not convinced yet the name should be toJSON since it already receives the output of the serialization 🤔, did you think of any alternative name?

from structure.

talyssonoc avatar talyssonoc commented on June 18, 2024

Actually, after discussing with some other contributors there are some raised concerns about it:

  • Serialization is not the main goal of this lib, and in case some deeper rules for serialization are needed they should be built outside of the structure, like a UserSerializer.serialize(userStructure)
  • If we ever add this option, this should not be a static method, the idea of using a decorator is exactly to avoid polluting the class with non-business logic
  • Right now our validation process depends on serialization so we can pass POJOs to Joi, this should be taken into consideration to avoid confusion during validation

After considering these points, I'm not sure anymore if we should add this feature.

from structure.

loweoj avatar loweoj commented on June 18, 2024

Yup makes sense. Thanks for the input guys.

from structure.

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.