
Enables PHP serialization format support, facilitating encoding and decoding of various types like strings, integers, and custom classes. Supports comprehensive type compatibility, excluding sets and partial sealed class support.
This is a Kotlin library that provides PHP serialization format support for kotlinx.serialization.
It supports some kotlin targets(JVM, iOS, Android)
Add the following dependency to your build.gradle.kts or build.gradle file:
dependencies {
implementation("com.jsoizo:kotlinx-serialization-php:0.1.0")
}encoding
@Serializable
data class User(val id: Int, val name: String)
val user = User(id = 100, name = "John")
val php = PHP()
val encoded = php.encodeToString(user)
// "O:4:\"User\":2:{s:2:\"id\";i:100;s:4:\"name\";s:4:\"John\";}"decoding
val encoded = "O:4:\"User\":2:{s:2:\"id\";i:100;s:4:\"name\";s:4:\"John\";}"
val php = PHP()
val decodedUser = php.decodeFromString<User>(encoded)
// User(id=100, name="John")To see more usage and examples, please refer to the kotlinx.serialization documentation
Kotlin types that can be serialized to and deserialized from PHP serialization format.
| Kotlin type | Supported | PHP Serialization type |
|---|---|---|
String |
✅ | s |
Char |
✅ | s |
Int |
✅ | i |
Long |
✅ | i |
Float |
✅ | d |
Double |
✅ | d |
Boolean |
✅ | b |
List |
✅ | a |
Map |
✅ | a |
Set |
🚫 | |
class with @Serializable |
✅ | O |
enum class |
✅ | E |
sealed class |
O |
|
Nullable |
✅ | N |
This is a Kotlin library that provides PHP serialization format support for kotlinx.serialization.
It supports some kotlin targets(JVM, iOS, Android)
Add the following dependency to your build.gradle.kts or build.gradle file:
dependencies {
implementation("com.jsoizo:kotlinx-serialization-php:0.1.0")
}encoding
@Serializable
data class User(val id: Int, val name: String)
val user = User(id = 100, name = "John")
val php = PHP()
val encoded = php.encodeToString(user)
// "O:4:\"User\":2:{s:2:\"id\";i:100;s:4:\"name\";s:4:\"John\";}"decoding
val encoded = "O:4:\"User\":2:{s:2:\"id\";i:100;s:4:\"name\";s:4:\"John\";}"
val php = PHP()
val decodedUser = php.decodeFromString<User>(encoded)
// User(id=100, name="John")To see more usage and examples, please refer to the kotlinx.serialization documentation
Kotlin types that can be serialized to and deserialized from PHP serialization format.
| Kotlin type | Supported | PHP Serialization type |
|---|---|---|
String |
✅ | s |
Char |
✅ | s |
Int |
✅ | i |
Long |
✅ | i |
Float |
✅ | d |
Double |
✅ | d |
Boolean |
✅ | b |
List |
✅ | a |
Map |
✅ | a |
Set |
🚫 | |
class with @Serializable |
✅ | O |
enum class |
✅ | E |
sealed class |
O |
|
Nullable |
✅ | N |