Closed davidepedranz closed 7 years ago
I think the idea is interesting, but my gut says this library either needs a proper extensions API or it shouldn't do this. Kind of just bolting on features without much direction
Do you plan to provide an extension API?
I think an extension API to an extension is a bit of extensionception.
Could this be accomplished with a very simple delegating wrapper?
@AutoService(TypeAdapterFactory.class)public final class DelegatingTypeAdapterFactory implements TypeAdapterFactory {
private final SampleAdapterFactory delegate = SampleAdapterFactory.create();
@Override
@SuppressWarnings("unchecked")
public
I understand that's a little extra work, but something like this could be generated with a separate annotation processor that simply processes the @GsonTypeAdapterFactory annotation in addition to the current one.
On Wed, Aug 2, 2017 at 6:21 AM Davide Pedranz notifications@github.com wrote:
Do you plan to provide an extension API?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rharter/auto-value-gson/issues/140#issuecomment-319644055, or mute the thread https://github.com/notifications/unsubscribe-auth/ABPJbrL_k2QGqz9VzPiCzZfgHFQp07TUks5sUFutgaJpZM4Okdtj .
Thank you for the suggestion @rharter, I find it a very clean and elegant solution!
I will try to implement such an annotation processor. Let me know if you may be interested in adding it to this library in the future.
Hi, first of all thanks you for this great library!
Recently I faced the following problem problem. I am working on a project that uses many libraries to interact with various services in our platform. I use
auto-value
whenever I can andgson
together withauto-value-gson
for serialisation / deserialisation. I would like to be able to automatically register all classes annotated with@AutoValue
to my gson instance, even if they come from an external library.I would like a way to automatically register to
gson
allTypeAdapterFactory
present in the libraries. I think a solution could be to rely on the Java service loaders, something like this:I tried to register the abstract class annotated with
@GsonTypeAdapterFactory
as a service provider using@AutoService
, but Java fails to instantiate it since abstract. I propose it to optionally annotate the generatedTypeAdapterFactory
with@AutoService
, so that one can use the Java service provider to dynamically load all factories when needed.I though about a parameter to the
@GsonTypeAdapterFactory
to optionally enable this feature (disabled by default). So this class:will generate this implementation:
What do you think? If you like the idea, I would be happy to make a pull-request to implement this feature.