Coder Social home page Coder Social logo

Json Default Value to Lists? about kotshi HOT 12 CLOSED

ansman avatar ansman commented on May 29, 2024
Json Default Value to Lists?

from kotshi.

Comments (12)

ansman avatar ansman commented on May 29, 2024

I don’t really understand this issue, what you describe is already supported, in exactly the same way as in your example

from kotshi.

ademar111190 avatar ademar111190 commented on May 29, 2024

Sorry I was not clear.
What I was trying to say is why do not add this feature to the library, in the same way as the library already does with the defaultString and others.
Currently, everyone needs to add this same code to its project, so it is the motivation.

from kotshi.

ansman avatar ansman commented on May 29, 2024

I see your point, I need to think about this. One would probably want to name it JsonDefaultValueEmptyList and then we need to add the same for sets and maps.

from kotshi.

ademar111190 avatar ademar111190 commented on May 29, 2024

Sure.
I think the class can be more similar to the others and receive a value.

from kotshi.

ansman avatar ansman commented on May 29, 2024

Annotation values must be compile time constants so lists are no allowed, otherwise we could simply create a generic annotation that accepts default values for all types.

from kotshi.

ademar111190 avatar ademar111190 commented on May 29, 2024

I got it.
Given the limitation, I would say the idea to have the empties list, set, map, etc is good.

from kotshi.

JakeWharton avatar JakeWharton commented on May 29, 2024

from kotshi.

ansman avatar ansman commented on May 29, 2024

@JakeWharton It wouldn't work doing it in Moshi if you want a default value when the key is absent from the json.

from kotshi.

JakeWharton avatar JakeWharton commented on May 29, 2024

from kotshi.

ansman avatar ansman commented on May 29, 2024

If a key is absent from the Json the adapter for that field is never queried.

For example given this class:

public class Foo {
  public Bar bar;
}

and this json:

{}

the adapter for Bar would never be called.

from kotshi.

JakeWharton avatar JakeWharton commented on May 29, 2024

from kotshi.

ansman avatar ansman commented on May 29, 2024

Closing this, it's no longer relevant when #108 is merged

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.