kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Inline class can handle `{ "key": value }` JSON.

Open rockyoung opened this issue 3 years ago • 3 comments

In my app, i have many apis that require the transfer body in json format with only one element, like { "status": 0 }, { "name": "Sam" }, etc. so I think it would be great to use inline classes to decode them, avoiding a lot of runtime type definitions.

maybe have some option annotations or configs for these kind serializations of inline class?

rockyoung avatar May 27 '22 07:05 rockyoung

Sorry, I don't quite get the idea. You mean that you want inline classes to be serializable as regular classes, without any inlining?

sandwwraith avatar May 30 '22 11:05 sandwwraith

Sorry, I don't quite get the idea. You mean that you want inline classes to be serializable as regular classes, without any inlining?

yes, this is exactly what i mean.

rockyoung avatar Jun 08 '22 02:06 rockyoung

Note that this capability would be something in principle format independent (although some formats may not support inline classes as inline at all). A workaround may be to have a wrapper on the serializer that will just change the serialKind on inlines. But this needs to be applied carefully in case of polymorphism (the serialmodule must not return unwrapped serializers/descriptors).

pdvrieze avatar Jun 20 '22 13:06 pdvrieze