Giter VIP home page Giter VIP logo

Comments (11)

Petrulak avatar Petrulak commented on July 20, 2024 6

It would be pretty handy to have some default value since i am facing same issue.
For example i am fetching list of object from API , and some object doesn't have certain property, so only way how to fix is it to annotate field with @nullable or to alter read method in final class AutoValue_XYZ extends $AutoValue_XYZ which is pretty nasty adn harder to maintain if i want to add new fields. @rharter are you planning to implement some kind of default value in future ?
Thanks

from auto-value-gson.

rharter avatar rharter commented on July 20, 2024 1

I just released 0.4.5, it should be available soon.

from auto-value-gson.

autonomousapps avatar autonomousapps commented on July 20, 2024 1

Thanks again! AutoValue, auto-value-parcel, and auto-value-gson are helping me cut the size of my value classes in half (and also enforce immutability).

from auto-value-gson.

rharter avatar rharter commented on July 20, 2024

Can you please detail what you're asking for and why?

from auto-value-gson.

kjsolo avatar kjsolo commented on July 20, 2024
class User {
    String name;
    String nickname;
}

Sometime service does not pass nickname and application will crash, But I do not want use @nullable and check "null" every time.

from auto-value-gson.

autonomousapps avatar autonomousapps commented on July 20, 2024

The readme discusses support for default values, but I can't seem to get it to work. The following compiles:

@AutoValue public abstract class Lesson {

    public abstract long id();
    public abstract String name();

    public static TypeAdapter<Lesson> typeAdapter(Gson gson) {
        return new AutoValue_Lesson.GsonTypeAdapter(gson);
    }
}

But this does not:

@AutoValue public abstract class Lesson {

    public abstract long id();
    public abstract String name();

    public static TypeAdapter<Lesson> typeAdapter(Gson gson) {
        return new AutoValue_Lesson.GsonTypeAdapter(gson)
                .defaultId(0L)
                .defaultName("")
    }
}

The error looks like this:

Lesson.java:46: error: cannot find symbol
                .defaultName("");

I am including the library like so:

    provided "com.ryanharter.auto.value:auto-value-gson:0.4.4"
    apt "com.ryanharter.auto.value:auto-value-gson:0.4.4"

from auto-value-gson.

autonomousapps avatar autonomousapps commented on July 20, 2024

From the changelog, it looks like maybe default value support has not been released yet?

from auto-value-gson.

rharter avatar rharter commented on July 20, 2024

from auto-value-gson.

autonomousapps avatar autonomousapps commented on July 20, 2024

Do you have an estimate when that might be? Just curious. I can build locally if I have to.

from auto-value-gson.

rharter avatar rharter commented on July 20, 2024

from auto-value-gson.

autonomousapps avatar autonomousapps commented on July 20, 2024

Thank you!

from auto-value-gson.

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.