xinthink / auto-data-class Goto Github PK
View Code? Open in Web Editor NEWGenerator for Kotlin data classes with Gson/Parcelable type adapter
License: Apache License 2.0
Generator for Kotlin data classes with Gson/Parcelable type adapter
License: Apache License 2.0
Sample class that illustrates the error:
@DataClass data class Foo(val x: Int) {
var y: Int
get() = x + 1
}
The generated class attempts to read a y
property from the JSON object. It then instantiates Foo
by including y
in the constructor call, which is invalid and results in a compilation error.
I added dependencies to my gradle file:
implementation 'com.fivemiles.auto:auto-data-class-lib:0.5.3'
kapt 'com.fivemiles.auto:auto-data-class-processor:0.5.3'
There was an error in generated files:
DC_Message.kt: (8, 25): Unresolved reference: Generated
It seems that compiler cannot find javax.annotation.Generated
and we need to add additional dependency to resolve it.
Hi,
Thanks for it, it's great. I'm just filling an issue cause currently we can't add auto-data-class in an existing jetpack compose project we always end up with the following error when trying to build
e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;
Just to let you know (as compose is still in an early early stage it might come from this ;) )
Regards
I can use generic in AutoValue&Gson:
@AutoValue
public abstract class ObjectListResponse<T> {
public static <T> TypeAdapter<ObjectListResponse<T>> typeAdapter(
Gson gson, TypeToken<? extends ObjectListResponse<T>> typeToken) {
return new AutoValue_ObjectListResponse.GsonTypeAdapter<>(gson, typeToken);
}
@SerializedName("meta")
@NonNull public abstract MetaData getMetaData();
@SerializedName("objects")
@NonNull public abstract List<T> getObjects();
}
And after declaration I can use ObjectListResponse properly to simplify responses:
@GET("wallet")
Single<Response<ObjectListResponse<WalletPojo>>> getWallet(@Header("Authorization") String token);
I cannot declare the same behaviour with DataClass. I used the next interface:
@DataClass
interface ObjectListKey<T> {
@get:DataProp("meta")
val metaData: MetaKey
@get: DataProp("objects")
val objects: List<T>
}
And there were errors in generated files. Does anybody know how to declare behaviour with generics with DataClass?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.