ZacSweers / redacted-compiler-plugin

A Kotlin compiler plugin that generates redacted toString() implementations.
Apache License 2.0
382 stars 26 forks source link

Incompatible with kotlinx-serialization #56

Open edenman opened 2 years ago

edenman commented 2 years ago

Ok so https://github.com/ZacSweers/redacted-compiler-plugin/issues/16 and https://github.com/ZacSweers/redacted-compiler-plugin/issues/24 raised this, but I felt like it was worth reopening since redacting fields in a kotlinx @Serializable class actually seems like a very common usecase.

The problem: the compiler plugin infrastructure doesn't currently support multiple compiler plugins operating on the same class if they both need to look at the constructors of the class. Kotlinx serialization uses a compiler plugin, so Redacted's compiler breaks.

Possible solution: Add a KSP plugin to generate a new possiblyRedactedToString() method for all @Serializable classes. Then still use a compiler plugin to replace toString() but instead of doing it only if a @Redacted annotation is present, do it for all @Serializable classes.

I think this would work, but it's probably too niche to support for this library. What do you think?

ZacSweers commented 2 years ago

I think that would need to be a separate library. I do wish they'd offer better answers here for 3rd party plugins. What will happen when they break compose? "Sorry this wasn't supported anyway bye". Anvil has experienced similar issues as well.

edenman commented 2 years ago

Cool, thanks for the quick reply! I'll post here if I end up open-sourcing something