. I have read the appropriate documents (I think) and am using the appropriate annotations and strategies (I think), but I am still encountering a run-time issue immediately. I am also encountering a compile-time issue, I think, because the compiler doesn’t believe that there’s a
method on my
I am using
for everything I can, and
for the run-time.
This is my best guess at what versions I should be using, so I’d appreciate any correction if someone has it.
Eliding most of the stack for the moment and going to the root cause, at run-time I receive this error:
Caused by: kotlinx.serialization.SerializationException: Serializer for class 'TransformationRule' is not found. Mark the class as @Serializable or provide the serializer explicitly.
I have tried a number of variations on this scheme in order to extract more information or find a path to solution.
I am using JVM only, I should mention.
And I am using JSON as the serialization transport.
Also, this used to work. But somehow a project that I had not touched for a year atrophied in place, and I was no longer able to build it. After struggling with Gradle and/or IntelliJ, together or separately, for a whole day, I gave up and migrated everything forward to the latest versions. I have no remaining deprecation warnings — actually, I have no warnings of any kind — but the system fails at run-time with the error message that I reported above.
But I tried the workarounds described therein, and it did nothing for me; same situation after as before.
Here is my enclosing data class:
* A transformation encapsulates a rule and its static operands, and provides a
* simple API for applying the transformation to a [JSON element][JsonElement].
@Serializable(with = TransformationSerializer::class)
* Transform the specified [JSON element][JsonElement] by applying the
* encapsulated [transformation rule][TransformationRule]. If the supplied
* JSON element does not satisfy the preconditions of the rule, then it will
* not be transformed.
* @param source
* The JSON element, which is expected to satisfy the prerequisites of the
* The result of the transformation. `null` indicates that the object is
* being elided.
fun transform(source: JsonElement): JsonElement? =
It uses a custom serializer, primarily so that it can cope with two different representational strategies based on possible compactness:
I have no idea whether the code that I’ve written is correct, because I can’t even get past the basics. The plugin doesn’t appear to be generating the correct code for associating my
enum class TransformationRule
with its serializer (
Also worth mentioning perhaps, I’m neither a newcomer to Kotlin or to kotlinx-serialization. I have written several very large projects in Kotlin and I maintain a large project actively. I use Kotlin both at work and for play.
Okay, that’s all that I can think to volunteer without some engagement. I’ll check on this frequently, and would greatly appreciate any help that can be offered. Thanks in advance.
1 year ago
Your runtime version doesn't match your plugin version, try the latest runtime (
). There probably should be better errors if that mismatches, but the runtime is for Kotlin and plugin version
. If that doesn't help, try without custom serializers and see if it works. Everything looks correct to me though. I think Enums serialize to their names by default in the new version, too, so you probably don't need a custom serializer there.
1 year ago
Ah! It took me a bit to figure out how to set
in Gradle (the URL was eluding me), but that seems to have been the problem. Now it’s warning me that I’m using tons of experimental APIs, and it still crashes on startup, but with an error in my own code. Fingers crossed, but I should be able to trace it from here.
Thank you for your help, @rnett. Much appreciated!
FYI, I got everything working with my custom serializers. Thanks agin, @rnett. Really appreciate the help. 👍