Comments (11)
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.
I just released 0.4.5, it should be available soon.
from auto-value-gson.
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.
Can you please detail what you're asking for and why?
from auto-value-gson.
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.
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.
From the changelog, it looks like maybe default value support has not been released yet?
from auto-value-gson.
from auto-value-gson.
Do you have an estimate when that might be? Just curious. I can build locally if I have to.
from auto-value-gson.
from auto-value-gson.
Thank you!
from auto-value-gson.
Related Issues (20)
- MyClass_GsonTypeAdapter references non-existent intermediary AutoValue_MyClass class HOT 1
- Parse json object with varying data types
- RV_RETURN_VALUE_IGNORED findbugs error HOT 3
- Build failed in the generated read method for a generic class HOT 1
- Originating element not set HOT 3
- Generate proguard rules HOT 1
- Generic base types cause compile errors HOT 2
- Allow custom opt-in annotation for factory HOT 2
- AutoValueGsonExtension fails on immutable collections. HOT 1
- "Unable to get public no-arg constructor" simply when adding auto-value-gson dependency HOT 3
- auto-value-gson-from-rharter-generated-invalid-code HOT 6
- What dependency AutoValue annotation is in ? HOT 1
- Non-deterministic generation of TypeAdapterFactory HOT 2
- Issue using @GenerateTypeAdapter with maven HOT 2
- `@Nullable` doesn't work correctly with nested types
- NullPointerException processing ImmutableList.Builder Builder method
- Compilation error in Eclipse/maven
- Handling unrecognized json properties HOT 1
- @AutoValue.Builder generates objects with all fields HOT 2
- 也许这个方案更加好 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auto-value-gson.