Coder Social home page Coder Social logo

Transient fields are not ignored about kotshi HOT 6 CLOSED

ansman avatar ansman commented on May 30, 2024
Transient fields are not ignored

from kotshi.

Comments (6)

 avatar commented on May 30, 2024

If you do this, don't forget to allow setting a default value into the field when deserializing.

from kotshi.

ansman avatar ansman commented on May 30, 2024

It’s not that easy I’m afraid since you need all properties to be declared in the constructor. One solution is to enforce default values for transient properties but I’m not sure I like it. It feels a bit like this could be solved in a nicer way (in the client code that is)

from kotshi.

 avatar commented on May 30, 2024

Moshi supports transient, is there an argument that Kotshi shouldn't?

Consider:

@JsonSerializable
data class User(
    val name: String,
    val email: String,
    @Transient val sessionKeys: List<String> = listOf())

Yes you could put sessionKeys down in a separate property but then you lose out on all the benefits of data class for that field including copy constructors, hashing, and equals. And yes one could always model the transient data outside of the data class but that seems restrictive.

from kotshi.

 avatar commented on May 30, 2024

@bishiboosh hope you don't mind that I gave this a try!

from kotshi.

bishiboosh avatar bishiboosh commented on May 30, 2024

@gladed I was on holidays, so thank you ! I'll go check your PR :D

from kotshi.

 avatar commented on May 30, 2024

Tried it in 1.0.3 and it's working great, thanks for merging @ansman

from kotshi.

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.