Comments (2)
The way it can/should work is this in Kotlin < 1.3 (w/o any language changes):
@Serializable data class MyData(val x: Int)
@Serializable data class Box<T>(val v: T)
val b = Box(MyData(42))
JSON.stringify(b, Box.serializer(MyData)) // produces "{v: {x: 42}}" -- types are fully static
val c = JSON.parse("...", Box.serializer(MyData))
In short, the idea that for generic classes a serialier(...)
function in their companion object will be generated by serialization plugin. This function will have as many parameters as there are generic type parameters in the class, each parameter to the serializer
function being the corresponding serializer.
In Koltin 1.3 we can rollout experimental language support for serialization and redefine JSON.parse
function like this:
fun <serializable T> parse(): T
The serializable
modifier is going to work similarly to reified
(with or without the need for inline
). It will plug the corresponding type-specific serializer as an additional parameter to the parse
function behind the scenes. Inside the parse
it could be accessed like T::serializer
.
from kotlinx.serialization.
Generic user classes supported (modulo bugs) in 0.3 with syntax described here
from kotlinx.serialization.
Related Issues (20)
- Didn't find class "kotlinx.serialization.json.Json" on path: DexPathList HOT 1
- typealiased @Serializable cannot be used as type hints HOT 1
- Value classes not using encodeInlineElement and inefficient boxing of primitive values
- Errors revealed only on run-time HOT 1
- ERROR: org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationResolveExtension caused LinkageError HOT 3
- Allow annotation meta-annotations with Serializable
- Streaming performance: kotlinx-io & Okio integrations
- kotlinx.serialization.json deserialize error HOT 1
- Quoted booleans are being allowed even with `isLenient = false` HOT 6
- very strange serialization HOT 2
- The built-in String type (JsonPrimitive/JsonLiteral) puts double quotes around the string value HOT 8
- Don't check kind if needn't type discriminator for enum and primitive HOT 5
- 2.0.20 with generatedSerializer and reference to interface: SealedClassSerializer init: subclassSerializers contains null HOT 2
- [protobuf] How to encode/decode map with null value?
- Option to serialize enums as lowercase/snake_case HOT 4
- hande single quotes when `isLenient=true` HOT 3
- Support for `serializer<@Contextual T>` HOT 3
- Not a Bug But missing step in the Documentation when working with KMP HOT 1
- "Serializer for class List is not found" on Native. HOT 2
- [FEATURE] Allow defining a sealed class as a subclass of an open polymorphic class HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlinx.serialization.