kotlinx-serialization-php

About
This is a Kotlin Multiplatform library that provides PHP serialization format support for kotlinx.serialization.
Installation
Add the following dependency to your build.gradle.kts or build.gradle file:
dependencies {
implementation("com.jsoizo:kotlinx-serialization-php:0.2.1")
}
Usage
encoding
@Serializable
data class User(val id: Int, val name: String)
val user = User(id = 100, name = "John")
val encoded = PHP.encodeToString(user)
decoding
val encoded = "O:4:\"User\":2:{s:2:\"id\";i:100;s:4:\"name\";s:4:\"John\";}"
val decodedUser = PHP.decodeFromString<User>(encoded)
To customize the behavior, build a configured instance with the PHP {} builder:
val php = PHP {
ignoreUnknownKeys = true
serializersModule = SerializersModule { }
}
val decoded = php.decodeFromString<User>(encoded)
PHP serializes protected properties as "\0*\0name" and private ones as
"\0ClassName\0name"; these are automatically matched to the Kotlin property
by their bare name when decoding.
To see more usage and examples, please refer to the kotlinx.serialization documentation
Supported types
Kotlin types that can be serialized to and deserialized from PHP serialization format.
Float.NaN and infinities are mapped to PHP's NAN / INF / -INF in both
directions. Map keys must be Int, Long, String or because PHP
array keys can only be integers or strings; other key types fail with
.
Supported Platforms
- JVM
- Android
- Native (iOS, macOS, Linux, Windows)
- JS
- WebAssembly (wasm-js, wasm-wasi)
Limitations