はじめに
「Kotlinブログ 「kotlinx.serialization 1.0 released」を翻訳してみた」に引き続き、「Kotlin Serialization ガイド」を訳してみました。
なお、翻訳にはDeepLの力を99%借りています。
もし、一緒に翻訳をして下さる方がいらっしゃいましたら、コメント欄などから連絡をください。
「Kotlin Serialization ガイド」 翻訳
Latest commit 728e220 on 24 Nov 2020版
Kotlin Serialization は、クロスプラットフォームで、且つマルチフォーマットのデータシリアライズフレームワークで、更にオブジェクトのツリーを文字列、バイト配列、その他のシリアル表現に変換し、戻すことができます。Kotlin Serialization は Kotlin の型システムを完全にサポートしており、有効なオブジェクトのみがデシリアライズできるようになっています。
Kotlin Serialization は単なるライブラリではありません。Kotlin コンパイラのディストリビューション自体にバンドルされているコンパイラプラグインです。ビルドの設定はREADME.md(日本語)に説明されています。プロジェクトのセットアップが完了したら、いくつかのクラスのシリアライズを開始します。
| Table of contents | 目次 |
|---|---|
| Chapter 1. Basic Serialization (start reading here) | 第1章 基本的なシリアライゼーション (ここから読み始める) |
| ・Basics | ・基礎知識 |
| JSON encoding | JSON エンコーディング |
| JSON decoding | JSON デコーディング |
| ・Serializable classes | ・シリアライゼーション クラス |
| Backing fields are serialized | バッキングフィールドはシリアル化されている |
| Constructor properties requirement | コンストラクタのプロパティ要件 |
| Data validation | データの検証 |
| Optional properties | オプションのプロパティ |
| Optional property initializer call | オプションのプロパティイニシャライザ呼び出し |
| Required properties | 必要なプロパティ |
| Transient properties | 過渡特性 |
| Defaults are not encoded | デフォルトはエンコードされていません。 |
| Nullable properties | ヌル許容なプロパティ |
| Type safety is enforced | タイプの安全性が強化されている |
| Referenced objects | 参照オブジェクト |
| No compression of repeated references | 繰り返し参照の圧縮なし |
| Generic classes | ジェネリッククラス |
| Serial field names | シリアルフィールドの名前 |
| Chapter 2. Builtin Classes | 第2章 ビルトインクラス |
| ・Primitives | ・プリミティブ |
| Numbers | 数字 |
| Long numbers | 長い数字 |
| Long numbers as strings | 文字列としての長い数字 |
| Enum classes | 列挙クラス |
| Serial names of enum entries | 列挙エントリの連番名 |
| ・Composites | ・コンポジット |
| Pair and triple | ペアとトリプル |
| Lists | リスト |
| Sets and other collections | セットとその他のコレクション |
| Deserializing collections | コレクションのデシリアライズ |
| Maps | マップ |
| Unit and singleton objects | ユニットオブジェクトとシングルトンオブジェクト |
| Chapter 3. Serializers | 第3章 シリアライザ |
| ・Introduction to serializers | ・シリアライザの紹介 |
| Plugin-generated serializer | プラグインで生成されたシリアライザ |
| Plugin-generated generic serializer | プラグインで生成された汎用シリアライザ |
| Builtin primitive serializers | 組み込みのプリミティブシリアライザ |
| Constructing collection serializers | コレクション・シリアライザの構築 |
| Using top-level serializer function | トップレベルのシリアライザ機能の使用 |
| ・Custom serializers | ・カスタムシリアライザ |
| Primitive serializer | 原始的なシリアライザ |
| Composite serializer via surrogate | サロゲートを介した複合シリアライザ |
| Hand-written composite serializer | 手書き複合シリアライザ |
| Sequential decoding protocol (experimental) | 逐次復号化プロトコル(実験) |
| Serializing 3rd party classes | サードパーティクラスのシリアライズ |
| Passing a serializer manually | シリアライザを手動で渡す |
| Specifying serializer on a property | プロパティでのシリアライザの指定 |
| Specifying serializers for a file | ファイルのシリアライザを指定する |
| Custom serializers for a generic type | 汎用型のカスタムシリアライザ |
| Format-specific serializers | フォーマット固有のシリアライザ |
| ・Contextual serialization | ・コンテクストに応じたシリアル化 |
| Serializers module | シリアライザモジュール |
| ・Deriving external serializer for another Kotlin class (experimental) | ・別の Kotlin クラスのための外部シリアライザの導出 (実験的) |
| External serialization uses properties | 外部シリアライズはプロパティを使用します。 |
| Chapter 4. Polymorphism | 第4章 ポリモフィズム |
| ・Closed polymorphism | ・閉ざされたポリモフィズム |
| Static types | 静的な型 |
| Designing serializable hierarchy | シリアライズ可能な階層の設計 |
| Sealed classes | シールドされたクラス |
| Custom subclass serial name | カスタムサブクラスのシリアル名 |
| Concrete properties in a base class | 基底クラスの具体的なプロパティ |
| Objects | オブジェクト |
| ・Open polymorphism | ・開放的なポリモーフィズム |
| Registered subclasses | 登録されたサブクラス |
| Serializing interfaces | インターフェイスのシリアライズ |
| Property of an interface type | インターフェース型のプロパティ |
| Static parent type lookup for polymorphism | ポリモフィズムのための静的な親型検索 |
| Explicitly marking polymorphic class properties | ポリモフィズムクラスのプロパティを明示的にマークする |
| Registering multiple superclasses | スーパークラスを複数登録する |
| Polymorphism and generic classes | ポリモーフィズムとジェネリッククラス |
| Merging library serializers modules | ライブラリのシリアライザモジュールをマージ |
| Default polymorphic type handler for deserialization | デシリアライゼーションのためのデフォルトのポリモフィズム型ハンドラ |
| Chapter 5. JSON Features | 第5章 JSONの機能 |
| ・Json configuration | ・Json設定 |
| Pretty printing | きれいな印刷 |
| Lenient parsing | 簡潔な構文解析 |
| Ignoring unknown keys | 未知のキーを無視する |
| Coercing input values | 入力値の強制 |
| Encoding defaults | デフォルトのエンコーディング |
| Allowing structured map keys | 構造化されたマップキーの許可 |
| Allowing special floating-point values | 特殊な浮動小数点値の許可 |
| Class discriminator | クラス識別器 |
| ・Json elements | ・Json要素 |
| Parsing to Json element | Json要素へのパース |
| Subtypes of Json elements | Json要素のサブタイプ |
| Json element builders | Json要素のビルダー |
| Decoding Json element | Json要素のデコード |
| ・Json transformations | ・Json の変換 |
| Array wrapping | 配列のラッピング |
| Array unwrapping | 配列のアンラップ |
| Manipulating default values | デフォルト値の操作 |
| Content-based polymorphic deserialization | コンテンツベースのポリモーフィックデシリアライゼーション |
| Under the hood (experimental) | ボンネットの下(実験) |
| Maintaining custom JSON attributes | カスタムJSON属性のメンテナンス |
| Chapter 6. Alternative and custom formats (experimental) | 第6章 書き方の工夫 代替フォーマットとカスタムフォーマット(実験) |
| ・CBOR (experimental) | ・CBOR (実験) |
| Ignoring unknown keys | じっけん |
| Byte arrays and CBOR data types | 未知のキーを無視する |
| ・ProtoBuf (experimental) | ・ProtoBuf (実験) |
| Field numbers | フィールドの番号 |
| Integer types | 整数型 |
| Lists as repeated fields | 繰り返しフィールドとしてのリスト |
| ・Properties (experimental) | ・Properties (実験) |
| ・Custom formats (experimental) | ・Custom formats (実験) |
| Basic encoder | 基本的なエンコーダ |
| Basic decoder | 基本デコーダ |
| Sequential decoding | 逐次復号化 |
| Adding collection support | コレクションサポートの追加 |
| Adding null support | nullサポートの追加 |
| Efficient binary format | 効率的なバイナリ形式 |
| Format-specific types | フォーマット固有の型 |