├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature-request---design-discussion.md ├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── copyright │ ├── kotlinx_serialization.xml │ └── profiles_settings.xml └── vcs.xml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── RELEASING.md ├── benchmark ├── build.gradle.kts └── src │ └── jmh │ ├── kotlin │ └── kotlinx │ │ └── benchmarks │ │ ├── cbor │ │ └── CborBaseLine.kt │ │ ├── json │ │ ├── CitmBenchmark.kt │ │ ├── CoerceInputValuesBenchmark.kt │ │ ├── ContextualOverheadBenchmark.kt │ │ ├── ImplicitNullsBenchmark.kt │ │ ├── JacksonComparisonBenchmark.kt │ │ ├── LookupOverheadBenchmark.kt │ │ ├── PolymorphismOverheadBenchmark.kt │ │ ├── PrimitiveValuesBenchmark.kt │ │ ├── TwitterBenchmark.kt │ │ ├── TwitterFeedBenchmark.kt │ │ ├── TwitterFeedCommentsBenchmark.kt │ │ ├── TwitterFeedStreamBenchmark.kt │ │ ├── UseSerializerOverheadBenchmark.kt │ │ └── moshi │ │ │ └── MoshiBaseline.kt │ │ ├── model │ │ ├── Citm.kt │ │ ├── MacroTwitter.kt │ │ ├── MacroTwitterUntailored.kt │ │ ├── PixelEvents.kt │ │ └── Twitter.kt │ │ └── protobuf │ │ ├── ProtoBaseline.kt │ │ ├── ProtoHuge.kt │ │ ├── ProtoListBenchmark.kt │ │ ├── ProtoListLikeBenchmark.kt │ │ └── ProtoMapBenchmark.kt │ └── resources │ ├── citm_catalog.json │ ├── twitter.json │ └── twitter_macro.json ├── bom └── build.gradle.kts ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── gradle.properties ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── Java9Modularity.kt │ ├── Projects.kt │ ├── animalsniffer-conventions.gradle.kts │ ├── benchmark-conventions.gradle.kts │ ├── bom-conventions.gradle.kts │ ├── dokka-conventions.gradle.kts │ ├── global-compiler-options.gradle.kts │ ├── kover-conventions.gradle.kts │ ├── native-targets-conventions.gradle.kts │ ├── publishing-check-conventions.gradle.kts │ ├── publishing-conventions.gradle.kts │ ├── source-sets-conventions.gradle.kts │ ├── teamcity-conventions.gradle.kts │ └── utils.kt ├── core ├── api │ ├── kotlinx-serialization-core.api │ └── kotlinx-serialization-core.klib.api ├── build.gradle.kts ├── commonMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ ├── Annotations.kt │ │ ├── ApiLevels.kt │ │ ├── ContextualSerializer.kt │ │ ├── KSerializer.kt │ │ ├── PolymorphicSerializer.kt │ │ ├── SealedSerializer.kt │ │ ├── SerialFormat.kt │ │ ├── SerializationExceptions.kt │ │ ├── Serializers.kt │ │ ├── SerializersCache.kt │ │ ├── builtins │ │ ├── BuiltinSerializers.kt │ │ └── LongAsStringSerializer.kt │ │ ├── descriptors │ │ ├── ContextAware.kt │ │ ├── SerialDescriptor.kt │ │ ├── SerialDescriptors.kt │ │ └── SerialKinds.kt │ │ ├── encoding │ │ ├── AbstractDecoder.kt │ │ ├── AbstractEncoder.kt │ │ ├── ChunkedDecoder.kt │ │ ├── Decoding.kt │ │ └── Encoding.kt │ │ ├── internal │ │ ├── AbstractPolymorphicSerializer.kt │ │ ├── BuiltInSerializers.kt │ │ ├── CachedNames.kt │ │ ├── CollectionDescriptors.kt │ │ ├── CollectionSerializers.kt │ │ ├── ElementMarker.kt │ │ ├── Enums.kt │ │ ├── InlineClassDescriptor.kt │ │ ├── JsonInternalDependencies.kt │ │ ├── NamedCompanion.kt │ │ ├── NoOpEncoder.kt │ │ ├── NothingSerialDescriptor.kt │ │ ├── NullableSerializer.kt │ │ ├── ObjectSerializer.kt │ │ ├── Platform.common.kt │ │ ├── PluginExceptions.kt │ │ ├── PluginGeneratedSerialDescriptor.kt │ │ ├── PluginHelperInterfaces.kt │ │ ├── PrimitiveArraysSerializers.kt │ │ ├── Primitives.kt │ │ ├── SerializationConstructorMarker.kt │ │ ├── Tagged.kt │ │ ├── Tuples.kt │ │ └── ValueClasses.kt │ │ └── modules │ │ ├── PolymorphicModuleBuilder.kt │ │ ├── SerializersModule.kt │ │ ├── SerializersModuleBuilders.kt │ │ └── SerializersModuleCollector.kt ├── commonTest │ └── src │ │ └── kotlinx │ │ └── serialization │ │ ├── BasicTypesSerializationTest.kt │ │ ├── CachedSerializersTest.kt │ │ ├── CustomPropertyAccessorsTest.kt │ │ ├── ElementMarkerTest.kt │ │ ├── EnumDescriptorsTest.kt │ │ ├── InheritableSerialInfoTest.kt │ │ ├── InterfaceContextualSerializerTest.kt │ │ ├── MetaSerializableTest.kt │ │ ├── PolymorphismTestData.kt │ │ ├── PrimitiveSerialDescriptorTest.kt │ │ ├── SealedGenericClassesTest.kt │ │ ├── SerialDescriptorAnnotationsTest.kt │ │ ├── SerialDescriptorBuilderTest.kt │ │ ├── SerialDescriptorEqualityTest.kt │ │ ├── SerialDescriptorSpecificationTest.kt │ │ ├── SerializersLookupEnumTest.kt │ │ ├── SerializersLookupInterfaceTest.kt │ │ ├── SerializersLookupNamedCompanionTest.kt │ │ ├── SerializersLookupObjectTest.kt │ │ ├── SerializersModuleTest.kt │ │ ├── TaggedTest.kt │ │ ├── TestId.kt │ │ ├── UmbrellaTypes.kt │ │ ├── WrappedSerialDescriptorTest.kt │ │ ├── features │ │ ├── SchemaTest.kt │ │ └── SealedInterfacesSerializationTest.kt │ │ ├── internal │ │ ├── DummySequentialDecoder.kt │ │ ├── ObjectSerializerTest.kt │ │ └── TuplesTest.kt │ │ ├── modules │ │ ├── ContextualGenericsTest.kt │ │ └── ModuleBuildersTest.kt │ │ └── test │ │ ├── CompilerVersions.kt │ │ ├── CurrentPlatform.common.kt │ │ └── TestHelpers.kt ├── jsMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ ├── SerializersJs.kt │ │ └── internal │ │ └── Platform.kt ├── jsTest │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── test │ │ └── CurrentPlatform.kt ├── jvmMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ ├── SerializersJvm.kt │ │ └── internal │ │ ├── Caching.kt │ │ ├── Platform.kt │ │ └── SuppressAnimalSniffer.kt ├── jvmMainModule │ └── src │ │ └── module-info.java ├── jvmTest │ └── src │ │ └── kotlinx │ │ └── serialization │ │ ├── CachingTest.kt │ │ ├── InterfaceContextualSerializerTestJvm.kt │ │ ├── RetentionTest.kt │ │ ├── SerializationMethodInvocationOrderTest.kt │ │ ├── SerializeFlatTest.kt │ │ ├── features │ │ ├── JvmContextualGenericsTest.kt │ │ └── SerializerJvmSpecificTest.kt │ │ ├── privateclasstest │ │ └── PrivateDataOutOfKotlinXSerializationPackageTest.kt │ │ └── test │ │ ├── CurrentPlatform.kt │ │ └── TypeToken.kt ├── nativeMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ ├── Serializers.kt │ │ └── internal │ │ └── Platform.kt ├── nativeTest │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── test │ │ └── CurrentPlatform.kt ├── wasmMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ ├── Serializers.kt │ │ └── internal │ │ └── Platform.kt └── wasmTest │ └── src │ └── kotlinx │ └── serialization │ └── test │ └── CurrentPlatform.kt ├── docs ├── basic-serialization.md ├── building.md ├── builtin-classes.md ├── compatibility.md ├── formats.md ├── inline-classes.md ├── json.md ├── knit.properties ├── migration.md ├── polymorphism.md ├── serialization-guide.md ├── serializers.md └── value-classes.md ├── dokka-templates └── README.md ├── dokka └── moduledoc.md ├── formats ├── README.md ├── cbor │ ├── api │ │ ├── kotlinx-serialization-cbor.api │ │ └── kotlinx-serialization-cbor.klib.api │ ├── build.gradle.kts │ ├── commonMain │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── cbor │ │ │ ├── ByteString.kt │ │ │ ├── Cbor.kt │ │ │ ├── CborArray.kt │ │ │ ├── CborConfiguration.kt │ │ │ ├── CborDecoder.kt │ │ │ ├── CborEncoder.kt │ │ │ ├── CborLabel.kt │ │ │ ├── Tags.kt │ │ │ └── internal │ │ │ ├── CborDecodingException.kt │ │ │ ├── Decoder.kt │ │ │ ├── Encoder.kt │ │ │ ├── Encoding.kt │ │ │ ├── Streams.kt │ │ │ └── SuppressAnimalSniffer.kt │ ├── commonTest │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ ├── HexConverter.kt │ │ │ ├── PolymorphismTestData.kt │ │ │ ├── TestUtilities.kt │ │ │ └── cbor │ │ │ ├── CborArrayTest.kt │ │ │ ├── CborDecoderTest.kt │ │ │ ├── CborDefiniteLengthTest.kt │ │ │ ├── CborIsoTest.kt │ │ │ ├── CborLabelTest.kt │ │ │ ├── CborNumberEncodingTest.kt │ │ │ ├── CborParserTest.kt │ │ │ ├── CborPolymorphismTest.kt │ │ │ ├── CborRootLevelNullsTest.kt │ │ │ ├── CborSkipTagAndEmptyTest.kt │ │ │ ├── CborTaggedTest.kt │ │ │ ├── CborWriterTest.kt │ │ │ └── SampleClasses.kt │ ├── jvmMainModule │ │ └── src │ │ │ └── module-info.java │ └── jvmTest │ │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── cbor │ │ ├── CborCompatibilityTest.kt │ │ ├── CborStacktraceRecoveryTest.kt │ │ ├── CborWriterSpecTest.kt │ │ ├── RandomTests.kt │ │ └── TestUtilities.kt ├── hocon │ ├── api │ │ └── kotlinx-serialization-hocon.api │ ├── build.gradle.kts │ └── src │ │ ├── main │ │ └── kotlin │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── hocon │ │ │ ├── Hocon.kt │ │ │ ├── HoconDecoder.kt │ │ │ ├── HoconEncoder.kt │ │ │ ├── HoconEncoders.kt │ │ │ ├── HoconExceptions.kt │ │ │ ├── HoconSerialKind.kt │ │ │ ├── NamingConvention.kt │ │ │ ├── internal │ │ │ ├── HoconDuration.kt │ │ │ └── SuppressAnimalSniffer.kt │ │ │ └── serializers │ │ │ ├── ConfigMemorySizeSerializer.kt │ │ │ └── JavaDurationSerializer.kt │ │ ├── mainModule │ │ └── kotlin │ │ │ └── module-info.java │ │ └── test │ │ └── kotlin │ │ └── kotlinx │ │ └── serialization │ │ └── hocon │ │ ├── HoconDurationTest.kt │ │ ├── HoconEncoderTest.kt │ │ ├── HoconJavaDurationTest.kt │ │ ├── HoconMemorySizeTest.kt │ │ ├── HoconNamingConventionTest.kt │ │ ├── HoconObjectsTest.kt │ │ ├── HoconPolymorphismTest.kt │ │ ├── HoconRootObjectsTest.kt │ │ ├── HoconTesting.kt │ │ └── HoconValuesTest.kt ├── json-io │ ├── api │ │ ├── kotlinx-serialization-json-io.api │ │ └── kotlinx-serialization-json-io.klib.api │ ├── build.gradle.kts │ ├── commonMain │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── json │ │ │ └── io │ │ │ ├── IoStreams.kt │ │ │ └── internal │ │ │ └── IoJsonStreams.kt │ └── commonTest │ │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── json │ │ └── io │ │ └── IoTests.kt ├── json-okio │ ├── api │ │ ├── kotlinx-serialization-json-okio.api │ │ └── kotlinx-serialization-json-okio.klib.api │ ├── build.gradle.kts │ ├── commonMain │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── json │ │ │ └── okio │ │ │ ├── OkioStreams.kt │ │ │ └── internal │ │ │ └── OkioJsonStreams.kt │ ├── commonTest │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── json │ │ │ └── okio │ │ │ └── internal │ │ │ └── OkioTests.kt │ └── dokka │ │ └── okio.package.list ├── json-tests │ ├── build.gradle.kts │ ├── commonTest │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ ├── ClassWithMultipleMasksTest.kt │ │ │ ├── EncodingCollectionsTest.kt │ │ │ ├── EncodingExtensionsTest.kt │ │ │ ├── EnumSerializationTest.kt │ │ │ ├── GenericOverrideTest.kt │ │ │ ├── GenericSerializersOnFileTest.kt │ │ │ ├── JsonElementPolymorphicErrorTest.kt │ │ │ ├── JsonOverwriteKeyTest.kt │ │ │ ├── JsonPathTest.kt │ │ │ ├── KeepGeneratedSerializerTest.kt │ │ │ ├── NotNullSerializersCompatibilityOnFileTest.kt │ │ │ ├── PolymorphismTestData.kt │ │ │ ├── SerializableClasses.kt │ │ │ ├── SerializableOnPropertyTypeAndTypealiasTest.kt │ │ │ ├── SerializationForNullableTypeOnFileTest.kt │ │ │ ├── SerializerForNullableTypeTest.kt │ │ │ ├── SerializersLookupTest.kt │ │ │ ├── TuplesTest.kt │ │ │ ├── UmbrellaTypes.kt │ │ │ ├── UnknownElementIndexTest.kt │ │ │ ├── builtins │ │ │ └── KeyValueSerializersTest.kt │ │ │ ├── features │ │ │ ├── BinaryPayloadExampleTest.kt │ │ │ ├── ByteArraySerializerTest.kt │ │ │ ├── CollectionSerializerTest.kt │ │ │ ├── ContextAndPolymorphicTest.kt │ │ │ ├── DefaultPolymorphicSerializerTest.kt │ │ │ ├── DerivedContextualSerializerTest.kt │ │ │ ├── DurationTest.kt │ │ │ ├── EmojiTest.kt │ │ │ ├── GenericCustomSerializerTest.kt │ │ │ ├── InheritanceTest.kt │ │ │ ├── JsonClassDiscriminatorTest.kt │ │ │ ├── JsonCommentsTest.kt │ │ │ ├── JsonEnumsCaseInsensitiveTest.kt │ │ │ ├── JsonNamesTest.kt │ │ │ ├── JsonNamingStrategyExclusionTest.kt │ │ │ ├── JsonNamingStrategyTest.kt │ │ │ ├── LocalClassesTest.kt │ │ │ ├── LongAsStringTest.kt │ │ │ ├── MetaSerializableJsonTest.kt │ │ │ ├── ObjectSerialization.kt │ │ │ ├── PartiallyCustomSerializerTest.kt │ │ │ ├── PolymorphicDeserializationErrorMessagesTest.kt │ │ │ ├── PolymorphicOnClassesTest.kt │ │ │ ├── PolymorphismForCustomTest.kt │ │ │ ├── PolymorphismTest.kt │ │ │ ├── PolymorphismWithAnyTest.kt │ │ │ ├── PrimitiveArraySerializersTest.kt │ │ │ ├── PropertyInitializerTest.kt │ │ │ ├── SealedClassesSerializationTest.kt │ │ │ ├── SealedPolymorphismTest.kt │ │ │ ├── SerializableOnTypeUsageTest.kt │ │ │ ├── SerializableWithTest.kt │ │ │ ├── SkipDefaults.kt │ │ │ ├── UseSerializersTest.kt │ │ │ ├── UuidTest.kt │ │ │ ├── inline │ │ │ │ ├── EncodeInlineElementTest.kt │ │ │ │ ├── InlineClassesCompleteTest.kt │ │ │ │ ├── InlineClassesTest.kt │ │ │ │ ├── InlineMapQuotedTest.kt │ │ │ │ ├── UnsignedIntegersTest.kt │ │ │ │ └── ValueClassesInSealedHierarchyTest.kt │ │ │ └── sealed │ │ │ │ ├── SealedChild.kt │ │ │ │ ├── SealedDiamondTest.kt │ │ │ │ ├── SealedInterfacesInlineSerialNameTest.kt │ │ │ │ ├── SealedInterfacesJsonSerializationTest.kt │ │ │ │ └── SealedParent.kt │ │ │ ├── json │ │ │ ├── AbstractJsonImplicitNullsTest.kt │ │ │ ├── BasicTypesSerializationTest.kt │ │ │ ├── DecodeFromJsonElementTest.kt │ │ │ ├── JsonBuildersTest.kt │ │ │ ├── JsonChunkedStringDecoderTest.kt │ │ │ ├── JsonCoerceInputValuesTest.kt │ │ │ ├── JsonConfigurationTest.kt │ │ │ ├── JsonCustomSerializersTest.kt │ │ │ ├── JsonDefaultContextTest.kt │ │ │ ├── JsonElementDecodingTest.kt │ │ │ ├── JsonEncoderDecoderRecursiveTest.kt │ │ │ ├── JsonErrorMessagesTest.kt │ │ │ ├── JsonExponentTest.kt │ │ │ ├── JsonGenericTest.kt │ │ │ ├── JsonHugeDataSerializationTest.kt │ │ │ ├── JsonIgnoreKeysTest.kt │ │ │ ├── JsonImplicitNullsTest.kt │ │ │ ├── JsonMapKeysTest.kt │ │ │ ├── JsonModesTest.kt │ │ │ ├── JsonNumericKeysTest.kt │ │ │ ├── JsonOptionalTests.kt │ │ │ ├── JsonParserFailureModesTest.kt │ │ │ ├── JsonParserTest.kt │ │ │ ├── JsonPrettyPrintTest.kt │ │ │ ├── JsonReifiedCollectionsTest.kt │ │ │ ├── JsonRootLevelNullTest.kt │ │ │ ├── JsonSealedSubclassTest.kt │ │ │ ├── JsonTestBase.kt │ │ │ ├── JsonTransformingSerializerTest.kt │ │ │ ├── JsonTransientTest.kt │ │ │ ├── JsonTreeAndMapperTest.kt │ │ │ ├── JsonTreeImplicitNullsTest.kt │ │ │ ├── JsonTreeTest.kt │ │ │ ├── JsonUnicodeTest.kt │ │ │ ├── JsonUnionEnumTest.kt │ │ │ ├── JsonUpdateModeTest.kt │ │ │ ├── LenientTest.kt │ │ │ ├── MapLikeSerializerTest.kt │ │ │ ├── SpecialFloatingPointValuesTest.kt │ │ │ ├── TrailingCommaTest.kt │ │ │ ├── polymorphic │ │ │ │ ├── JsonClassDiscriminatorModeBaseTest.kt │ │ │ │ ├── JsonClassDiscriminatorModeTest.kt │ │ │ │ ├── JsonContentPolymorphicSerializerTest.kt │ │ │ │ ├── JsonDeserializePolymorphicTwiceTest.kt │ │ │ │ ├── JsonListPolymorphismTest.kt │ │ │ │ ├── JsonMapPolymorphismTest.kt │ │ │ │ ├── JsonNestedPolymorphismTest.kt │ │ │ │ ├── JsonNullablePolymorphicTest.kt │ │ │ │ ├── JsonPolymorphicClassDescriptorTest.kt │ │ │ │ ├── JsonPolymorphicObjectTest.kt │ │ │ │ ├── JsonPolymorphismExceptionTest.kt │ │ │ │ ├── JsonProhibitedPolymorphicKindsTest.kt │ │ │ │ ├── JsonPropertyPolymorphicTest.kt │ │ │ │ ├── JsonTreeDecoderPolymorphicTest.kt │ │ │ │ └── PolymorphicClasses.kt │ │ │ └── serializers │ │ │ │ ├── JsonArraySerializerTest.kt │ │ │ │ ├── JsonNativePrimitivesTest.kt │ │ │ │ ├── JsonNullSerializerTest.kt │ │ │ │ ├── JsonObjectSerializerTest.kt │ │ │ │ ├── JsonPrimitiveSerializerTest.kt │ │ │ │ ├── JsonSerializerInGenericsTest.kt │ │ │ │ ├── JsonTreeTest.kt │ │ │ │ ├── JsonUnquotedLiteralTest.kt │ │ │ │ └── Primitives.kt │ │ │ ├── modules │ │ │ ├── SerialNameCollisionInSealedClassesTest.kt │ │ │ └── SerialNameCollisionTest.kt │ │ │ └── test │ │ │ ├── ContextualTest.kt │ │ │ ├── CurrentPlatform.common.kt │ │ │ ├── InternalHexConverter.kt │ │ │ ├── JsonHelpers.kt │ │ │ ├── TestHelpers.kt │ │ │ ├── TestId.kt │ │ │ └── TestingFramework.kt │ ├── jsTest │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ ├── json │ │ │ ├── DecodeFromDynamicSpecialCasesTest.kt │ │ │ ├── DecodeFromDynamicTest.kt │ │ │ ├── DynamicPolymorphismTest.kt │ │ │ ├── DynamicToLongTest.kt │ │ │ ├── EncodeToDynamicSpecialCasesTest.kt │ │ │ ├── EncodeToDynamicTest.kt │ │ │ ├── JsonCoerceInputValuesDynamicTest.kt │ │ │ ├── JsonDynamicImplicitNullsTest.kt │ │ │ ├── JsonNamesDynamicTest.kt │ │ │ └── JsonNamingStrategyDynamicTest.kt │ │ │ └── test │ │ │ ├── CurrentPlatform.kt │ │ │ └── JsonHelpers.kt │ ├── jvmTest │ │ ├── resources │ │ │ ├── class_loaders │ │ │ │ └── classes │ │ │ │ │ └── example │ │ │ │ │ ├── Foo$$serializer.class │ │ │ │ │ ├── Foo$Companion.class │ │ │ │ │ └── Foo.class │ │ │ ├── corner_cases │ │ │ │ ├── listing.txt │ │ │ │ ├── number_1.0.json │ │ │ │ ├── number_1.000000000000000005.json │ │ │ │ ├── number_1000000000000000.json │ │ │ │ ├── number_10000000000000000999.json │ │ │ │ ├── number_1e-999.json │ │ │ │ ├── number_1e6.json │ │ │ │ ├── object_key_nfc_nfd.json │ │ │ │ ├── object_key_nfd_nfc.json │ │ │ │ ├── object_same_key_different_values.json │ │ │ │ ├── object_same_key_same_value.json │ │ │ │ ├── object_same_key_unclear_values.json │ │ │ │ ├── string_1_escaped_invalid_codepoint.json │ │ │ │ ├── string_1_invalid_codepoint.json │ │ │ │ ├── string_2_escaped_invalid_codepoints.json │ │ │ │ ├── string_2_invalid_codepoints.json │ │ │ │ ├── string_3_escaped_invalid_codepoints.json │ │ │ │ ├── string_3_invalid_codepoints.json │ │ │ │ └── string_with_escaped_NULL.json │ │ │ ├── corpus.zip │ │ │ └── spec_cases │ │ │ │ ├── listing.txt │ │ │ │ ├── listing_comments.txt │ │ │ │ ├── n_array_1_true_without_comma.json │ │ │ │ ├── n_array_a_invalid_utf8.json │ │ │ │ ├── n_array_colon_instead_of_comma.json │ │ │ │ ├── n_array_comma_after_close.json │ │ │ │ ├── n_array_comma_and_number.json │ │ │ │ ├── n_array_double_comma.json │ │ │ │ ├── n_array_double_extra_comma.json │ │ │ │ ├── n_array_extra_close.json │ │ │ │ ├── n_array_extra_comma.json │ │ │ │ ├── n_array_incomplete.json │ │ │ │ ├── n_array_incomplete_invalid_value.json │ │ │ │ ├── n_array_inner_array_no_comma.json │ │ │ │ ├── n_array_invalid_utf8.json │ │ │ │ ├── n_array_items_separated_by_semicolon.json │ │ │ │ ├── n_array_just_comma.json │ │ │ │ ├── n_array_just_minus.json │ │ │ │ ├── n_array_missing_value.json │ │ │ │ ├── n_array_newlines_unclosed.json │ │ │ │ ├── n_array_number_and_comma.json │ │ │ │ ├── n_array_number_and_several_commas.json │ │ │ │ ├── n_array_spaces_vertical_tab_formfeed.json │ │ │ │ ├── n_array_star_inside.json │ │ │ │ ├── n_array_unclosed.json │ │ │ │ ├── n_array_unclosed_trailing_comma.json │ │ │ │ ├── n_array_unclosed_with_new_lines.json │ │ │ │ ├── n_array_unclosed_with_object_inside.json │ │ │ │ ├── n_incomplete_false.json │ │ │ │ ├── n_incomplete_null.json │ │ │ │ ├── n_incomplete_true.json │ │ │ │ ├── n_multidigit_number_then_00.json │ │ │ │ ├── n_object_bad_value.json │ │ │ │ ├── n_object_bracket_key.json │ │ │ │ ├── n_object_comma_instead_of_colon.json │ │ │ │ ├── n_object_double_colon.json │ │ │ │ ├── n_object_emoji.json │ │ │ │ ├── n_object_garbage_at_end.json │ │ │ │ ├── n_object_key_with_single_quotes.json │ │ │ │ ├── n_object_lone_continuation_byte_in_key_and_trailing_comma.json │ │ │ │ ├── n_object_missing_colon.json │ │ │ │ ├── n_object_missing_key.json │ │ │ │ ├── n_object_missing_semicolon.json │ │ │ │ ├── n_object_missing_value.json │ │ │ │ ├── n_object_no-colon.json │ │ │ │ ├── n_object_non_string_key.json │ │ │ │ ├── n_object_non_string_key_but_huge_number_instead.json │ │ │ │ ├── n_object_repeated_null_null.json │ │ │ │ ├── n_object_several_trailing_commas.json │ │ │ │ ├── n_object_single_quote.json │ │ │ │ ├── n_object_trailing_comma.json │ │ │ │ ├── n_object_trailing_comment.json │ │ │ │ ├── n_object_trailing_comment_open.json │ │ │ │ ├── n_object_trailing_comment_slash_open.json │ │ │ │ ├── n_object_trailing_comment_slash_open_incomplete.json │ │ │ │ ├── n_object_two_commas_in_a_row.json │ │ │ │ ├── n_object_unquoted_key.json │ │ │ │ ├── n_object_unterminated-value.json │ │ │ │ ├── n_object_with_single_string.json │ │ │ │ ├── n_object_with_trailing_garbage.json │ │ │ │ ├── n_single_space.json │ │ │ │ ├── n_string_1_surrogate_then_escape.json │ │ │ │ ├── n_string_1_surrogate_then_escape_u.json │ │ │ │ ├── n_string_1_surrogate_then_escape_u1.json │ │ │ │ ├── n_string_1_surrogate_then_escape_u1x.json │ │ │ │ ├── n_string_accentuated_char_no_quotes.json │ │ │ │ ├── n_string_backslash_00.json │ │ │ │ ├── n_string_escape_x.json │ │ │ │ ├── n_string_escaped_backslash_bad.json │ │ │ │ ├── n_string_escaped_ctrl_char_tab.json │ │ │ │ ├── n_string_escaped_emoji.json │ │ │ │ ├── n_string_incomplete_escape.json │ │ │ │ ├── n_string_incomplete_escaped_character.json │ │ │ │ ├── n_string_incomplete_surrogate.json │ │ │ │ ├── n_string_incomplete_surrogate_escape_invalid.json │ │ │ │ ├── n_string_invalid-utf-8-in-escape.json │ │ │ │ ├── n_string_invalid_backslash_esc.json │ │ │ │ ├── n_string_invalid_unicode_escape.json │ │ │ │ ├── n_string_invalid_utf8_after_escape.json │ │ │ │ ├── n_string_leading_uescaped_thinspace.json │ │ │ │ ├── n_string_no_quotes_with_bad_escape.json │ │ │ │ ├── n_string_single_doublequote.json │ │ │ │ ├── n_string_single_quote.json │ │ │ │ ├── n_string_single_string_no_double_quotes.json │ │ │ │ ├── n_string_start_escape_unclosed.json │ │ │ │ ├── n_string_unescaped_crtl_char.json │ │ │ │ ├── n_string_unescaped_newline.json │ │ │ │ ├── n_string_unescaped_tab.json │ │ │ │ ├── n_string_unicode_CapitalU.json │ │ │ │ ├── n_string_with_trailing_garbage.json │ │ │ │ ├── n_structure_100000_opening_arrays.json │ │ │ │ ├── n_structure_U+2060_word_joined.json │ │ │ │ ├── n_structure_UTF8_BOM_no_data.json │ │ │ │ ├── n_structure_angle_bracket_..json │ │ │ │ ├── n_structure_angle_bracket_null.json │ │ │ │ ├── n_structure_array_trailing_garbage.json │ │ │ │ ├── n_structure_array_with_extra_array_close.json │ │ │ │ ├── n_structure_array_with_unclosed_string.json │ │ │ │ ├── n_structure_ascii-unicode-identifier.json │ │ │ │ ├── n_structure_capitalized_True.json │ │ │ │ ├── n_structure_close_unopened_array.json │ │ │ │ ├── n_structure_comma_instead_of_closing_brace.json │ │ │ │ ├── n_structure_double_array.json │ │ │ │ ├── n_structure_end_array.json │ │ │ │ ├── n_structure_incomplete_UTF8_BOM.json │ │ │ │ ├── n_structure_lone-invalid-utf-8.json │ │ │ │ ├── n_structure_lone-open-bracket.json │ │ │ │ ├── n_structure_no_data.json │ │ │ │ ├── n_structure_null-byte-outside-string.json │ │ │ │ ├── n_structure_number_with_trailing_garbage.json │ │ │ │ ├── n_structure_object_followed_by_closing_object.json │ │ │ │ ├── n_structure_object_unclosed_no_value.json │ │ │ │ ├── n_structure_object_with_comment.json │ │ │ │ ├── n_structure_object_with_trailing_garbage.json │ │ │ │ ├── n_structure_open_array_apostrophe.json │ │ │ │ ├── n_structure_open_array_comma.json │ │ │ │ ├── n_structure_open_array_object.json │ │ │ │ ├── n_structure_open_array_open_object.json │ │ │ │ ├── n_structure_open_array_open_string.json │ │ │ │ ├── n_structure_open_array_string.json │ │ │ │ ├── n_structure_open_object.json │ │ │ │ ├── n_structure_open_object_close_array.json │ │ │ │ ├── n_structure_open_object_comma.json │ │ │ │ ├── n_structure_open_object_open_array.json │ │ │ │ ├── n_structure_open_object_open_string.json │ │ │ │ ├── n_structure_open_object_string_with_apostrophes.json │ │ │ │ ├── n_structure_open_open.json │ │ │ │ ├── n_structure_single_star.json │ │ │ │ ├── n_structure_trailing_#.json │ │ │ │ ├── n_structure_uescaped_LF_before_string.json │ │ │ │ ├── n_structure_unclosed_array.json │ │ │ │ ├── n_structure_unclosed_array_partial_null.json │ │ │ │ ├── n_structure_unclosed_array_unfinished_false.json │ │ │ │ ├── n_structure_unclosed_array_unfinished_true.json │ │ │ │ ├── n_structure_unclosed_object.json │ │ │ │ ├── n_structure_unicode-identifier.json │ │ │ │ ├── n_structure_whitespace_U+2060_word_joiner.json │ │ │ │ ├── n_structure_whitespace_formfeed.json │ │ │ │ ├── y_array_arraysWithSpaces.json │ │ │ │ ├── y_array_empty-string.json │ │ │ │ ├── y_array_empty.json │ │ │ │ ├── y_array_ending_with_newline.json │ │ │ │ ├── y_array_false.json │ │ │ │ ├── y_array_heterogeneous.json │ │ │ │ ├── y_array_null.json │ │ │ │ ├── y_array_with_1_and_newline.json │ │ │ │ ├── y_array_with_leading_space.json │ │ │ │ ├── y_array_with_several_null.json │ │ │ │ ├── y_array_with_trailing_space.json │ │ │ │ ├── y_number.json │ │ │ │ ├── y_number_0e+1.json │ │ │ │ ├── y_number_0e1.json │ │ │ │ ├── y_number_after_space.json │ │ │ │ ├── y_number_double_close_to_zero.json │ │ │ │ ├── y_number_int_with_exp.json │ │ │ │ ├── y_number_minus_zero.json │ │ │ │ ├── y_number_negative_int.json │ │ │ │ ├── y_number_negative_one.json │ │ │ │ ├── y_number_negative_zero.json │ │ │ │ ├── y_number_real_capital_e.json │ │ │ │ ├── y_number_real_capital_e_neg_exp.json │ │ │ │ ├── y_number_real_capital_e_pos_exp.json │ │ │ │ ├── y_number_real_exponent.json │ │ │ │ ├── y_number_real_fraction_exponent.json │ │ │ │ ├── y_number_real_neg_exp.json │ │ │ │ ├── y_number_real_pos_exponent.json │ │ │ │ ├── y_number_simple_int.json │ │ │ │ ├── y_number_simple_real.json │ │ │ │ ├── y_object.json │ │ │ │ ├── y_object_basic.json │ │ │ │ ├── y_object_duplicated_key.json │ │ │ │ ├── y_object_duplicated_key_and_value.json │ │ │ │ ├── y_object_empty.json │ │ │ │ ├── y_object_empty_key.json │ │ │ │ ├── y_object_escaped_null_in_key.json │ │ │ │ ├── y_object_extreme_numbers.json │ │ │ │ ├── y_object_long_strings.json │ │ │ │ ├── y_object_simple.json │ │ │ │ ├── y_object_string_unicode.json │ │ │ │ ├── y_object_with_newlines.json │ │ │ │ ├── y_string_1_2_3_bytes_UTF-8_sequences.json │ │ │ │ ├── y_string_accepted_surrogate_pair.json │ │ │ │ ├── y_string_accepted_surrogate_pairs.json │ │ │ │ ├── y_string_allowed_escapes.json │ │ │ │ ├── y_string_backslash_and_u_escaped_zero.json │ │ │ │ ├── y_string_backslash_doublequotes.json │ │ │ │ ├── y_string_comments.json │ │ │ │ ├── y_string_double_escape_a.json │ │ │ │ ├── y_string_double_escape_n.json │ │ │ │ ├── y_string_escaped_control_character.json │ │ │ │ ├── y_string_escaped_noncharacter.json │ │ │ │ ├── y_string_in_array.json │ │ │ │ ├── y_string_in_array_with_leading_space.json │ │ │ │ ├── y_string_last_surrogates_1_and_2.json │ │ │ │ ├── y_string_nbsp_uescaped.json │ │ │ │ ├── y_string_nonCharacterInUTF-8_U+10FFFF.json │ │ │ │ ├── y_string_nonCharacterInUTF-8_U+FFFF.json │ │ │ │ ├── y_string_null_escape.json │ │ │ │ ├── y_string_one-byte-utf-8.json │ │ │ │ ├── y_string_pi.json │ │ │ │ ├── y_string_reservedCharacterInUTF-8_U+1BFFF.json │ │ │ │ ├── y_string_simple_ascii.json │ │ │ │ ├── y_string_space.json │ │ │ │ ├── y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json │ │ │ │ ├── y_string_three-byte-utf-8.json │ │ │ │ ├── y_string_two-byte-utf-8.json │ │ │ │ ├── y_string_u+2028_line_sep.json │ │ │ │ ├── y_string_u+2029_par_sep.json │ │ │ │ ├── y_string_uEscape.json │ │ │ │ ├── y_string_uescaped_newline.json │ │ │ │ ├── y_string_unescaped_char_delete.json │ │ │ │ ├── y_string_unicode.json │ │ │ │ ├── y_string_unicodeEscapedBackslash.json │ │ │ │ ├── y_string_unicode_2.json │ │ │ │ ├── y_string_unicode_U+10FFFE_nonchar.json │ │ │ │ ├── y_string_unicode_U+1FFFE_nonchar.json │ │ │ │ ├── y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json │ │ │ │ ├── y_string_unicode_U+2064_invisible_plus.json │ │ │ │ ├── y_string_unicode_U+FDD0_nonchar.json │ │ │ │ ├── y_string_unicode_U+FFFE_nonchar.json │ │ │ │ ├── y_string_unicode_escaped_double_quote.json │ │ │ │ ├── y_string_utf8.json │ │ │ │ ├── y_string_with_del_character.json │ │ │ │ ├── y_structure_lonely_false.json │ │ │ │ ├── y_structure_lonely_int.json │ │ │ │ ├── y_structure_lonely_negative_real.json │ │ │ │ ├── y_structure_lonely_null.json │ │ │ │ ├── y_structure_lonely_string.json │ │ │ │ ├── y_structure_lonely_true.json │ │ │ │ ├── y_structure_string_empty.json │ │ │ │ ├── y_structure_trailing_newline.json │ │ │ │ ├── y_structure_true_in_array.json │ │ │ │ └── y_structure_whitespace_array.json │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ ├── BigDecimalTest.kt │ │ │ ├── JavaCollectionsTest.kt │ │ │ ├── JvmMissingFieldsExceptionTest.kt │ │ │ ├── SerializationCasesTest.kt │ │ │ ├── SerializeJavaClassTest.kt │ │ │ ├── SerializerByTypeCacheTest.kt │ │ │ ├── SerializerForNullableJavaTypeTest.kt │ │ │ ├── StacktraceRecoveryTest.kt │ │ │ ├── UuidPlatformClashTest.kt │ │ │ ├── features │ │ │ ├── ContextualSerializationOnFileTest.kt │ │ │ ├── InternalInheritanceTest.kt │ │ │ ├── JsonJvmStreamsTest.kt │ │ │ ├── JsonLazySequenceTest.kt │ │ │ ├── JsonSequencePathTest.kt │ │ │ └── SerializerByTypeTest.kt │ │ │ ├── json │ │ │ ├── GsonCompatibilityTest.kt │ │ │ ├── JsonChunkedBase64DecoderTest.kt │ │ │ ├── JsonConcurrentStressTest.kt │ │ │ ├── MissingFieldExceptionWithPathTest.kt │ │ │ └── SpecConformanceTest.kt │ │ │ └── test │ │ │ ├── CurrentPlatform.kt │ │ │ ├── JsonHelpers.kt │ │ │ └── TypeToken.kt │ ├── nativeTest │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ ├── json │ │ │ └── MultiWorkerJsonTest.kt │ │ │ └── test │ │ │ ├── CurrentPlatform.kt │ │ │ └── JsonHelpers.kt │ └── wasmTest │ │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── test │ │ ├── CurrentPlatform.kt │ │ └── JsonHelpers.kt ├── json │ ├── api │ │ ├── kotlinx-serialization-json.api │ │ └── kotlinx-serialization-json.klib.api │ ├── build.gradle.kts │ ├── commonMain │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── json │ │ │ ├── Json.kt │ │ │ ├── JsonAnnotations.kt │ │ │ ├── JsonConfiguration.kt │ │ │ ├── JsonContentPolymorphicSerializer.kt │ │ │ ├── JsonDecoder.kt │ │ │ ├── JsonElement.kt │ │ │ ├── JsonElementBuilders.kt │ │ │ ├── JsonElementSerializers.kt │ │ │ ├── JsonEncoder.kt │ │ │ ├── JsonNamingStrategy.kt │ │ │ ├── JsonTransformingSerializer.kt │ │ │ └── internal │ │ │ ├── CharArrayPool.common.kt │ │ │ ├── Composers.kt │ │ │ ├── FormatLanguage.kt │ │ │ ├── JsonElementMarker.kt │ │ │ ├── JsonExceptions.kt │ │ │ ├── JsonIterator.kt │ │ │ ├── JsonNamesMap.kt │ │ │ ├── JsonPath.kt │ │ │ ├── JsonSerializersModuleValidator.kt │ │ │ ├── JsonStreams.kt │ │ │ ├── JsonToStringWriter.kt │ │ │ ├── JsonTreeReader.kt │ │ │ ├── Polymorphic.kt │ │ │ ├── SchemaCache.kt │ │ │ ├── StreamingJsonDecoder.kt │ │ │ ├── StreamingJsonEncoder.kt │ │ │ ├── StringOps.kt │ │ │ ├── SuppressAnimalSniffer.kt │ │ │ ├── TreeJsonDecoder.kt │ │ │ ├── TreeJsonEncoder.kt │ │ │ ├── WriteMode.kt │ │ │ └── lexer │ │ │ ├── AbstractJsonLexer.kt │ │ │ ├── CommentLexers.kt │ │ │ ├── ReaderJsonLexer.kt │ │ │ └── StringJsonLexer.kt │ ├── jsMain │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── json │ │ │ ├── Dynamics.kt │ │ │ └── internal │ │ │ ├── DynamicDecoders.kt │ │ │ └── DynamicEncoders.kt │ ├── jsWasmMain │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── json │ │ │ ├── JsonSchemaCache.kt │ │ │ └── internal │ │ │ ├── CharArrayPool.kt │ │ │ ├── FormatLanguageJsWasm.kt │ │ │ ├── JsonToStringWriterJsWasm.kt │ │ │ └── createMapForCache.kt │ ├── jvmMain │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── json │ │ │ ├── JsonSchemaCache.kt │ │ │ ├── JvmStreams.kt │ │ │ └── internal │ │ │ ├── ArrayPools.kt │ │ │ ├── CharsetReader.kt │ │ │ ├── FormatLanguage.kt │ │ │ ├── JsonToStringWriter.kt │ │ │ ├── JvmJsonStreams.kt │ │ │ └── createMapForCache.kt │ ├── jvmMainModule │ │ └── src │ │ │ └── module-info.java │ └── nativeMain │ │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── json │ │ ├── JsonSchemaCache.kt │ │ └── internal │ │ ├── CharArrayPool.kt │ │ ├── FormatLanguage.kt │ │ ├── JsonToStringWriter.kt │ │ └── createMapForCache.kt ├── properties │ ├── api │ │ ├── kotlinx-serialization-properties.api │ │ └── kotlinx-serialization-properties.klib.api │ ├── build.gradle.kts │ ├── commonMain │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── properties │ │ │ └── Properties.kt │ ├── commonTest │ │ └── src │ │ │ └── kotlinx │ │ │ └── serialization │ │ │ └── properties │ │ │ ├── PropertiesTest.kt │ │ │ └── SealedClassSerializationFromPropertiesTest.kt │ └── jvmMainModule │ │ └── src │ │ └── module-info.java └── protobuf │ ├── api │ ├── kotlinx-serialization-protobuf.api │ └── kotlinx-serialization-protobuf.klib.api │ ├── build.gradle.kts │ ├── commonMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── protobuf │ │ ├── ProtoBuf.kt │ │ ├── ProtoTypes.kt │ │ ├── internal │ │ ├── Helpers.kt │ │ ├── PackedArrayDecoder.kt │ │ ├── PackedArrayEncoder.kt │ │ ├── ProtobufDecoding.kt │ │ ├── ProtobufEncoding.kt │ │ ├── ProtobufReader.kt │ │ ├── ProtobufTaggedBase.kt │ │ ├── ProtobufTaggedDecoder.kt │ │ ├── ProtobufTaggedEncoder.kt │ │ ├── ProtobufWriter.kt │ │ ├── Streams.kt │ │ └── SuppressAnimalSniffer.kt │ │ └── schema │ │ └── ProtoBufSchemaGenerator.kt │ ├── commonTest │ └── src │ │ └── kotlinx │ │ └── serialization │ │ ├── HexConverter.kt │ │ ├── PolymorphismTestData.kt │ │ ├── TestUtils.kt │ │ ├── protobuf │ │ ├── AutoAssignIdsTest.kt │ │ ├── ByteArraySerializerTest.kt │ │ ├── CustomSerializersProtobufTest.kt │ │ ├── CustomizedSerializableTestClasses.kt │ │ ├── InvalidFieldNumberTest.kt │ │ ├── MapEntryTest.kt │ │ ├── PackedArraySerializerTest.kt │ │ ├── ProtoOneofInline.kt │ │ ├── ProtoTagExceptionTest.kt │ │ ├── ProtobufAbsenceTest.kt │ │ ├── ProtobufCollectionsTest.kt │ │ ├── ProtobufEnumTest.kt │ │ ├── ProtobufHugeClassTest.kt │ │ ├── ProtobufMissingFieldsTest.kt │ │ ├── ProtobufNothingTest.kt │ │ ├── ProtobufNullAndDefaultTest.kt │ │ ├── ProtobufOneOfTest.kt │ │ ├── ProtobufPolymorphismTest.kt │ │ ├── ProtobufPrimitiveWrappersTest.kt │ │ ├── ProtobufPrimitivesTest.kt │ │ ├── ProtobufTypeParameterTest.kt │ │ ├── ScatteredArraysTest.kt │ │ ├── SerializableTestClasses.kt │ │ ├── SkipFieldsTest.kt │ │ ├── TestFunctionTest.kt │ │ ├── TestFunctions.kt │ │ └── schema │ │ │ └── SchemaValidationsTest.kt │ │ └── test │ │ └── CurrentPlatform.common.kt │ ├── jsMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── protobuf │ │ └── internal │ │ └── Bytes.kt │ ├── jsTest │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── test │ │ └── CurrentPlatform.kt │ ├── jvmMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── protobuf │ │ └── internal │ │ └── Bytes.kt │ ├── jvmMainModule │ └── src │ │ └── module-info.java │ ├── jvmTest │ ├── resources │ │ ├── AbstractHolder.proto │ │ ├── ContextualHolder.proto │ │ ├── EnumWithProtoNumber.proto │ │ ├── FieldNumberClass.proto │ │ ├── LegacyMapHolder.proto │ │ ├── ListClass.proto │ │ ├── MapClass.proto │ │ ├── NestedCollections.proto │ │ ├── NullableNestedCollections.proto │ │ ├── OptionalClass.proto │ │ ├── OptionalCollections.proto │ │ ├── OptionsClass.proto │ │ ├── PackedListClass.proto │ │ ├── ScalarHolder.proto │ │ ├── SealedHolder.proto │ │ ├── SerialNameClass.proto │ │ └── common │ │ │ └── schema.proto │ └── src │ │ └── kotlinx │ │ └── serialization │ │ ├── protobuf │ │ ├── FormatConverterHelpers.kt │ │ ├── PolymorphicWithJvmClassTest.kt │ │ ├── ProtoBufNullTest.kt │ │ ├── ProtoBufOptionalTest.kt │ │ ├── ProtoCompatibilityTest.kt │ │ ├── ProtobufEnumWithSerialIdTest.kt │ │ ├── ProtobufTopLevelPrimitivesCompatibilityTest.kt │ │ ├── RandomTests.kt │ │ ├── conformance │ │ │ ├── Proto3EnumTest.kt │ │ │ ├── Proto3MapTest.kt │ │ │ ├── Proto3MessageTest.kt │ │ │ ├── Proto3OneofTest.kt │ │ │ ├── Proto3PackedTest.kt │ │ │ ├── Proto3PrimitiveTest.kt │ │ │ ├── Proto3RepeatedTest.kt │ │ │ └── Proto3UnpackedTest.kt │ │ └── schema │ │ │ ├── GenerationTest.kt │ │ │ └── RegenerateSchemas.kt │ │ └── test │ │ └── CurrentPlatform.kt │ ├── nativeMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── protobuf │ │ └── internal │ │ └── Bytes.kt │ ├── nativeTest │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── test │ │ └── CurrentPlatform.kt │ ├── proto-test-model │ ├── build.gradle.kts │ └── testProto │ │ ├── test_data.proto │ │ └── test_messages_proto3.proto │ ├── wasmMain │ └── src │ │ └── kotlinx │ │ └── serialization │ │ └── protobuf │ │ └── internal │ │ └── Bytes.kt │ └── wasmTest │ └── src │ └── kotlinx │ └── serialization │ └── test │ └── CurrentPlatform.kt ├── gradle.properties ├── gradle ├── artifacts.txt ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── guide ├── README.md ├── build.gradle.kts ├── example │ ├── example-basic-01.kt │ ├── example-basic-02.kt │ ├── example-basic-03.kt │ ├── example-builtin-01.kt │ ├── example-builtin-02.kt │ ├── example-builtin-03.kt │ ├── example-builtin-04.kt │ ├── example-builtin-05.kt │ ├── example-builtin-06.kt │ ├── example-builtin-07.kt │ ├── example-builtin-08.kt │ ├── example-builtin-09.kt │ ├── example-builtin-10.kt │ ├── example-builtin-11.kt │ ├── example-builtin-12.kt │ ├── example-builtin-13.kt │ ├── example-classes-01.kt │ ├── example-classes-02.kt │ ├── example-classes-03.kt │ ├── example-classes-04.kt │ ├── example-classes-05.kt │ ├── example-classes-06.kt │ ├── example-classes-07.kt │ ├── example-classes-08.kt │ ├── example-classes-09.kt │ ├── example-classes-10.kt │ ├── example-classes-11.kt │ ├── example-classes-12.kt │ ├── example-classes-13.kt │ ├── example-classes-14.kt │ ├── example-classes-15.kt │ ├── example-classes-16.kt │ ├── example-formats-01.kt │ ├── example-formats-02.kt │ ├── example-formats-03.kt │ ├── example-formats-04.kt │ ├── example-formats-05.kt │ ├── example-formats-06.kt │ ├── example-formats-07.kt │ ├── example-formats-08.kt │ ├── example-formats-09.kt │ ├── example-formats-10.kt │ ├── example-formats-11.kt │ ├── example-formats-12.kt │ ├── example-formats-13.kt │ ├── example-formats-14.kt │ ├── example-formats-15.kt │ ├── example-formats-16.kt │ ├── example-formats-17.kt │ ├── example-json-01.kt │ ├── example-json-02.kt │ ├── example-json-03.kt │ ├── example-json-04.kt │ ├── example-json-05.kt │ ├── example-json-06.kt │ ├── example-json-07.kt │ ├── example-json-08.kt │ ├── example-json-09.kt │ ├── example-json-10.kt │ ├── example-json-11.kt │ ├── example-json-12.kt │ ├── example-json-13.kt │ ├── example-json-14.kt │ ├── example-json-15.kt │ ├── example-json-16.kt │ ├── example-json-17.kt │ ├── example-json-18.kt │ ├── example-json-19.kt │ ├── example-json-20.kt │ ├── example-json-21.kt │ ├── example-json-22.kt │ ├── example-json-23.kt │ ├── example-json-24.kt │ ├── example-json-25.kt │ ├── example-json-26.kt │ ├── example-json-27.kt │ ├── example-json-28.kt │ ├── example-json-29.kt │ ├── example-json-30.kt │ ├── example-json-31.kt │ ├── example-json-32.kt │ ├── example-poly-01.kt │ ├── example-poly-02.kt │ ├── example-poly-03.kt │ ├── example-poly-04.kt │ ├── example-poly-05.kt │ ├── example-poly-06.kt │ ├── example-poly-07.kt │ ├── example-poly-08.kt │ ├── example-poly-09.kt │ ├── example-poly-10.kt │ ├── example-poly-11.kt │ ├── example-poly-12.kt │ ├── example-poly-13.kt │ ├── example-poly-14.kt │ ├── example-poly-15.kt │ ├── example-poly-16.kt │ ├── example-poly-17.kt │ ├── example-poly-18.kt │ ├── example-poly-19.kt │ ├── example-poly-20.kt │ ├── example-readme-01.kt │ ├── example-serializer-01.kt │ ├── example-serializer-02.kt │ ├── example-serializer-03.kt │ ├── example-serializer-04.kt │ ├── example-serializer-05.kt │ ├── example-serializer-06.kt │ ├── example-serializer-07.kt │ ├── example-serializer-08.kt │ ├── example-serializer-09.kt │ ├── example-serializer-10.kt │ ├── example-serializer-11.kt │ ├── example-serializer-12.kt │ ├── example-serializer-13.kt │ ├── example-serializer-14.kt │ ├── example-serializer-15.kt │ ├── example-serializer-16.kt │ ├── example-serializer-17.kt │ ├── example-serializer-18.kt │ ├── example-serializer-19.kt │ ├── example-serializer-20.kt │ ├── example-serializer-21.kt │ ├── example-serializer-22.kt │ ├── example-serializer-23.kt │ └── example-serializer-24.kt └── test │ ├── BasicSerializationTest.kt │ ├── BuiltinClassesTest.kt │ ├── FormatsTest.kt │ ├── JsonTest.kt │ ├── PolymorphismTest.kt │ ├── ReadmeTest.kt │ └── SerializersTest.kt ├── integration-test ├── build.gradle.kts ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── kotlin-js-store │ └── yarn.lock ├── settings.gradle.kts └── src │ ├── commonMain │ └── kotlin │ │ └── sample │ │ ├── Data.kt │ │ ├── GeoCoordinate.kt │ │ ├── MultiFileHierarchyModuleA.kt │ │ └── Sample.kt │ ├── commonTest │ └── kotlin │ │ └── sample │ │ ├── BasicTypesSerializationTest.kt │ │ ├── JsonTest.kt │ │ ├── MultiFileHierarchyModuleB.kt │ │ └── MultiFileHierarchyTest.kt │ ├── jsMain │ └── kotlin │ │ └── sample │ │ └── SampleJs.kt │ ├── jsTest │ └── kotlin │ │ └── sample │ │ └── SampleTestsJS.kt │ ├── jvmMain │ └── kotlin │ │ └── sample │ │ └── SampleJvm.kt │ ├── jvmTest │ └── kotlin │ │ └── sample │ │ └── SampleTestsJVM.kt │ ├── nativeMain │ └── kotlin │ │ └── sample │ │ └── SampleMacos.kt │ ├── nativeTest │ └── kotlin │ │ └── sample │ │ └── SampleTestsNative.kt │ ├── wasmJsMain │ └── kotlin │ │ └── sample │ │ └── SampleWasm.kt │ ├── wasmJsTest │ └── kotlin │ │ └── sample │ │ └── SampleTestsWasm.kt │ ├── wasmWasiMain │ └── kotlin │ │ └── sample │ │ └── SampleWasm.kt │ └── wasmWasiTest │ └── kotlin │ └── sample │ └── SampleTestsWasm.kt ├── knit.properties ├── kotlin-js-store └── yarn.lock ├── license ├── LICENSE.txt └── NOTICE.txt ├── rules ├── common.pro └── r8.pro └── settings.gradle.kts /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | 12 | **To Reproduce** 13 | Attach a code snippet or test data if possible. 14 | 15 | **Expected behavior** 16 | 17 | **Environment** 18 | - Kotlin version: [e.g. 1.3.30] 19 | - Library version: [e.g. 0.11.0] 20 | - Kotlin platforms: [e.g. JVM, JS, Native or their combinations] 21 | - Gradle version: [e.g. 4.10] 22 | - IDE version (if bug is related to the IDE) [e.g. IntellijIDEA 2019.1, Android Studio 3.4] 23 | - Other relevant context [e.g. OS version, JRE version, ... ] 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request---design-discussion.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request / design discussion 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: feature 6 | assignees: '' 7 | 8 | --- 9 | 10 | **What is your use-case and why do you need this feature?** 11 | 12 | **Describe the solution you'd like** 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # IntelliJ files 4 | **/.idea/* 5 | !/.idea/vcs.xml 6 | !/.idea/codeStyles 7 | !/.idea/copyright 8 | out/ 9 | *.iml 10 | 11 | # Gradle files 12 | build/ 13 | .gradle/ 14 | 15 | # Maven files 16 | target 17 | 18 | # Modules for JS projects build 19 | node_modules 20 | 21 | # benchmarks.jar 22 | /benchmarks.jar 23 | 24 | # Intermediate klibs 25 | .kotlin 26 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/copyright/kotlinx_serialization.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | 3 | This project and the corresponding community is governed by the [JetBrains Open Source and Community Code of Conduct](https://confluence.jetbrains.com/display/ALL/JetBrains+Open+Source+and+Community+Code+of+Conduct). Please make sure you read it. 4 | 5 | -------------------------------------------------------------------------------- /buildSrc/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.kotlin.dsl.allWarningsAsErrors=true 2 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Projects.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | import org.gradle.api.* 6 | import org.gradle.api.tasks.* 7 | 8 | val Project.sourceSets: SourceSetContainer 9 | get() = extensions.getByName("sourceSets") as SourceSetContainer 10 | 11 | fun Project.propertyIsTrue(propertyName: String): Boolean { 12 | return (findProperty(propertyName) as? String?).equals("true", true) 13 | } 14 | 15 | val Project.jdkToolchainVersion: Int get() = findProperty("jdk_toolchain_version").toString().toInt() 16 | 17 | val Project.overriddenLanguageVersion : String? 18 | get() = findProperty("kotlin_language_version") as String? 19 | 20 | val Project.teamcityInteractionEnabled : Boolean 21 | get() = !hasProperty("no_teamcity_interaction") && !hasProperty("build_snapshot_up") 22 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/bom-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | import org.gradle.kotlin.dsl.* 6 | import org.jetbrains.kotlin.gradle.dsl.* 7 | 8 | afterEvaluate { 9 | val isMultiplatform = plugins.hasPlugin("kotlin-multiplatform") 10 | 11 | if (isMultiplatform) { 12 | kotlinExtension.sourceSets.getByName("jvmMain").dependencies { 13 | api(project.dependencies.platform(project(bomProjectPath))) 14 | } 15 | } else { 16 | dependencies { 17 | "api"(platform(project(bomProjectPath))) 18 | } 19 | } 20 | } 21 | 22 | val bomProjectPath = ":kotlinx-serialization-bom" 23 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/teamcity-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | val teamcitySuffix = findProperty("teamcitySuffix")?.toString() 6 | if (teamcityInteractionEnabled && hasProperty("teamcity") && !propertyIsTrue("build_snapshot_train")) { 7 | // Tell teamcity about version number 8 | val postfix = if (teamcitySuffix == null) "" else " ($teamcitySuffix)" 9 | println("##teamcity[buildNumber '${project.version}${postfix}']") 10 | 11 | tasks.configureEach { 12 | doFirst { 13 | println("##teamcity[progressMessage 'Gradle: ${path}:${name}']") 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/utils.kt: -------------------------------------------------------------------------------- 1 | import java.util.Locale 2 | 3 | /* 4 | * Copyright 2017-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 5 | */ 6 | 7 | fun String.capitalizeCompat() = replaceFirstChar { 8 | if (it.isLowerCase()) it.titlecase(locale = Locale.getDefault()) else it.toString() 9 | } -------------------------------------------------------------------------------- /core/commonMain/src/kotlinx/serialization/internal/CachedNames.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | package kotlinx.serialization.internal 5 | 6 | import kotlinx.serialization.descriptors.* 7 | 8 | /** 9 | * Internal interface used as a marker for [SerialDescriptor] in order 10 | * to retrieve the set of all element names without allocations. 11 | * Used by our implementations as a performance optimization. 12 | * It's not an instance of [SerialDescriptor] to simplify implementation via delegation 13 | */ 14 | internal interface CachedNames { 15 | 16 | /** 17 | * A set of all names retrieved from [SerialDescriptor.getElementName] 18 | */ 19 | public val serialNames: Set 20 | } 21 | -------------------------------------------------------------------------------- /core/commonMain/src/kotlinx/serialization/internal/JsonInternalDependencies.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.internal 2 | 3 | import kotlinx.serialization.descriptors.* 4 | 5 | /* 6 | * Methods that are required for kotlinx-serialization-json, but are not effectively public. 7 | * 8 | * Anything marker with this annotation is not intended for public use. 9 | */ 10 | @RequiresOptIn(level = RequiresOptIn.Level.ERROR) 11 | internal annotation class CoreFriendModuleApi 12 | 13 | @CoreFriendModuleApi 14 | public fun SerialDescriptor.jsonCachedSerialNames(): Set = cachedSerialNames() 15 | -------------------------------------------------------------------------------- /core/commonMain/src/kotlinx/serialization/internal/NamedCompanion.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.internal 6 | 7 | import kotlinx.serialization.* 8 | 9 | /** 10 | * An annotation added by the compiler to the companion object of [Serializable] class, if it has a non-default name. 11 | */ 12 | @InternalSerializationApi 13 | @Target(AnnotationTarget.CLASS) 14 | @Retention(AnnotationRetention.RUNTIME) 15 | public annotation class NamedCompanion 16 | -------------------------------------------------------------------------------- /core/commonMain/src/kotlinx/serialization/internal/SerializationConstructorMarker.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.internal 6 | 7 | @Suppress("UNUSED") 8 | @Deprecated("Inserted into generated code and should not be used directly", level = DeprecationLevel.HIDDEN) 9 | public class SerializationConstructorMarker private constructor() 10 | -------------------------------------------------------------------------------- /core/commonTest/src/kotlinx/serialization/TestId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization 6 | 7 | import kotlinx.serialization.descriptors.* 8 | 9 | @SerialInfo 10 | @Target(AnnotationTarget.PROPERTY) 11 | annotation class Id(val id: Int) 12 | 13 | public fun getSerialId(desc: SerialDescriptor, index: Int): Int? 14 | = desc.findAnnotation(index)?.id 15 | 16 | public inline fun SerialDescriptor.findAnnotation(elementIndex: Int): A? { 17 | val candidates = getElementAnnotations(elementIndex).filterIsInstance() 18 | return when (candidates.size) { 19 | 0 -> null 20 | 1 -> candidates[0] 21 | else -> throw IllegalStateException("There are duplicate annotations of type ${A::class} in the descriptor $this") 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/commonTest/src/kotlinx/serialization/internal/ObjectSerializerTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.internal 6 | 7 | import kotlin.test.* 8 | import kotlinx.serialization.* 9 | 10 | class ObjectSerializerTest { 11 | @Test 12 | fun testSequentialDecoding() { 13 | SimpleObject.serializer().deserialize(DummySequentialDecoder()) 14 | } 15 | 16 | @Serializable 17 | object SimpleObject 18 | } 19 | -------------------------------------------------------------------------------- /core/commonTest/src/kotlinx/serialization/internal/TuplesTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.internal 6 | 7 | import kotlin.test.* 8 | import kotlinx.serialization.builtins.* 9 | 10 | class TuplesTest { 11 | @Test 12 | fun testSequentialDecodingKeyValue() { 13 | val decoder = DummySequentialDecoder() 14 | val serializer = MapEntrySerializer(Unit.serializer(), Unit.serializer()) 15 | serializer.deserialize(decoder) 16 | assertEquals(decoder.beginStructureCalled, decoder.endStructureCalled) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /core/commonTest/src/kotlinx/serialization/test/CurrentPlatform.common.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | enum class Platform { 8 | JVM, JS, NATIVE, WASM 9 | } 10 | 11 | public expect val currentPlatform: Platform 12 | 13 | public fun isJs(): Boolean = currentPlatform == Platform.JS 14 | public fun isJvm(): Boolean = currentPlatform == Platform.JVM 15 | public fun isNative(): Boolean = currentPlatform == Platform.NATIVE 16 | public fun isWasm(): Boolean = currentPlatform == Platform.WASM 17 | -------------------------------------------------------------------------------- /core/jsMain/src/kotlinx/serialization/SerializersJs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization 6 | 7 | import kotlin.reflect.* 8 | 9 | 10 | @OptIn(ExperimentalAssociatedObjects::class) 11 | @AssociatedObjectKey 12 | @Retention(AnnotationRetention.BINARY) 13 | @PublishedApi 14 | internal annotation class SerializableWith(public val serializer: KClass>) 15 | -------------------------------------------------------------------------------- /core/jsTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | public actual val currentPlatform: Platform = Platform.JS 8 | -------------------------------------------------------------------------------- /core/jvmMain/src/kotlinx/serialization/internal/SuppressAnimalSniffer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.internal 6 | 7 | /** 8 | * Suppresses Animal Sniffer plugin errors for certain classes. 9 | * Such classes are not available in Android API, but used only for JVM. 10 | */ 11 | @Retention(AnnotationRetention.BINARY) 12 | @Target(AnnotationTarget.CLASS) 13 | internal annotation class SuppressAnimalSniffer 14 | -------------------------------------------------------------------------------- /core/jvmMainModule/src/module-info.java: -------------------------------------------------------------------------------- 1 | module kotlinx.serialization.core { 2 | requires transitive kotlin.stdlib; 3 | 4 | exports kotlinx.serialization; 5 | exports kotlinx.serialization.builtins; 6 | exports kotlinx.serialization.descriptors; 7 | exports kotlinx.serialization.encoding; 8 | exports kotlinx.serialization.internal; 9 | exports kotlinx.serialization.modules; 10 | } 11 | -------------------------------------------------------------------------------- /core/jvmTest/src/kotlinx/serialization/RetentionTest.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization 2 | 3 | import org.junit.Test 4 | import kotlin.reflect.full.* 5 | import kotlin.test.* 6 | 7 | class RetentionTest { 8 | 9 | @Serializable 10 | class F(@SerialName("?") val a: Int, @Transient val b: Int = 42, @Required val c: Int) 11 | 12 | @Test 13 | fun testRetention() { 14 | assertEquals("?", F::a.findAnnotation()?.value) 15 | assertNotNull(F::b.findAnnotation()) 16 | assertNotNull(F::c.findAnnotation()) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /core/jvmTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | import kotlinx.serialization.test.Platform 8 | 9 | public actual val currentPlatform: Platform = Platform.JVM 10 | -------------------------------------------------------------------------------- /core/jvmTest/src/kotlinx/serialization/test/TypeToken.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | import java.lang.reflect.* 8 | 9 | // Same classes are present in SerializerByTypeTest.kt, 10 | // but it seems that json-jvm-test does not depend on core-jvm-test 11 | 12 | @PublishedApi 13 | internal open class TypeBase 14 | 15 | public inline fun typeTokenOf(): Type { 16 | val base = object : TypeBase() {} 17 | val superType = base::class.java.genericSuperclass!! 18 | return (superType as ParameterizedType).actualTypeArguments.first()!! 19 | } 20 | -------------------------------------------------------------------------------- /core/nativeMain/src/kotlinx/serialization/Serializers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization 6 | 7 | import kotlin.reflect.* 8 | 9 | @OptIn(ExperimentalAssociatedObjects::class) 10 | @AssociatedObjectKey 11 | @Retention(AnnotationRetention.BINARY) 12 | @PublishedApi 13 | internal annotation class SerializableWith(public val serializer: KClass>) 14 | -------------------------------------------------------------------------------- /core/nativeTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | import kotlinx.serialization.test.Platform 8 | 9 | public actual val currentPlatform: Platform = Platform.NATIVE 10 | -------------------------------------------------------------------------------- /core/wasmMain/src/kotlinx/serialization/Serializers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization 6 | 7 | import kotlin.reflect.* 8 | 9 | @OptIn(ExperimentalAssociatedObjects::class) 10 | @AssociatedObjectKey 11 | @Retention(AnnotationRetention.BINARY) 12 | @PublishedApi 13 | internal annotation class SerializableWith(public val serializer: KClass>) -------------------------------------------------------------------------------- /core/wasmTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | public actual val currentPlatform: Platform = Platform.WASM -------------------------------------------------------------------------------- /docs/inline-classes.md: -------------------------------------------------------------------------------- 1 | The documentation has been moved to the [value-classes.md](value-classes.md) page. 2 | -------------------------------------------------------------------------------- /docs/knit.properties: -------------------------------------------------------------------------------- 1 | knit.dir=../guide/example/ 2 | test.dir=../guide/test/ 3 | -------------------------------------------------------------------------------- /dokka-templates/README.md: -------------------------------------------------------------------------------- 1 | # Dokka's template customization 2 | To provide unified navigation for all parts of [kotlinlang.org](https://kotlinlang.org/), 3 | the Kotlin Website Team uses this directory to place custom templates in this folder 4 | during the website build time on TeamCity. 5 | 6 | It is not practical to place these templates in the kotlinx.serialization repository because they change from time to time 7 | and aren't related to the library's release cycle. 8 | 9 | The folder is defined as a source for custom templates by the templatesDir property through Dokka's plugin configuration. 10 | 11 | [Here](https://kotlin.github.io/dokka/1.7.20-SNAPSHOT/user_guide/output-formats/html/#custom-html-pages), you can 12 | find more about the customization of Dokka's HTML output. -------------------------------------------------------------------------------- /formats/cbor/commonMain/src/kotlinx/serialization/cbor/ByteString.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.cbor 2 | 3 | import kotlinx.serialization.* 4 | 5 | /** 6 | * Specifies that a [ByteArray] shall be encoded/decoded as CBOR major type 2: a byte string. 7 | * For types other than [ByteArray], [ByteString] will have no effect. 8 | * 9 | * Example usage: 10 | * 11 | * ``` 12 | * @Serializable 13 | * data class Data( 14 | * @ByteString 15 | * val a: ByteArray, // CBOR major type 2: a byte string. 16 | * 17 | * val b: ByteArray // CBOR major type 4: an array of data items. 18 | * ) 19 | * ``` 20 | * 21 | * See [RFC 7049 2.1. Major Types](https://tools.ietf.org/html/rfc7049#section-2.1). 22 | */ 23 | @SerialInfo 24 | @Target(AnnotationTarget.PROPERTY) 25 | @ExperimentalSerializationApi 26 | public annotation class ByteString 27 | -------------------------------------------------------------------------------- /formats/cbor/commonMain/src/kotlinx/serialization/cbor/internal/CborDecodingException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.cbor.internal 6 | 7 | import kotlinx.serialization.* 8 | 9 | internal class CborDecodingException(message: String) : SerializationException(message) 10 | 11 | @Suppress("FunctionName") 12 | internal fun CborDecodingException(expected: String, foundByte: Int) = 13 | CborDecodingException("Expected $expected, but found ${printByte(foundByte)}") 14 | 15 | internal fun printByte(b: Int): String { 16 | val hexCode = "0123456789ABCDEF" 17 | return buildString { 18 | append(hexCode[b shr 4 and 0xF]) 19 | append(hexCode[b and 0xF]) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /formats/cbor/commonMain/src/kotlinx/serialization/cbor/internal/SuppressAnimalSniffer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.cbor.internal 6 | 7 | /** 8 | * Suppresses Animal Sniffer plugin errors for certain methods. 9 | * Such methods include references to Java 8 methods that are not 10 | * available in Android API, but can be desugared by R8. 11 | */ 12 | @Retention(AnnotationRetention.BINARY) 13 | @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) 14 | internal annotation class SuppressAnimalSniffer 15 | -------------------------------------------------------------------------------- /formats/cbor/commonTest/src/kotlinx/serialization/cbor/CborRootLevelNullsTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.cbor 6 | 7 | import kotlinx.serialization.* 8 | import kotlinx.serialization.builtins.* 9 | import kotlin.test.* 10 | 11 | class CborRootLevelNullsTest { 12 | @Serializable 13 | data class Simple(val a: Int = 42) 14 | 15 | @Test 16 | fun testNull() { 17 | val obj: Simple? = null 18 | listOf(Cbor, Cbor { useDefiniteLengthEncoding = true }).forEach { 19 | val content = it.encodeToByteArray(Simple.serializer().nullable, obj) 20 | assertTrue(content.contentEquals(byteArrayOf(0xf6.toByte()))) 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /formats/cbor/jvmMainModule/src/module-info.java: -------------------------------------------------------------------------------- 1 | module kotlinx.serialization.cbor { 2 | requires transitive kotlin.stdlib; 3 | requires transitive kotlinx.serialization.core; 4 | 5 | exports kotlinx.serialization.cbor; 6 | } 7 | -------------------------------------------------------------------------------- /formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/HoconSerialKind.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.hocon 2 | 3 | import kotlinx.serialization.* 4 | import kotlinx.serialization.descriptors.* 5 | 6 | @OptIn(ExperimentalSerializationApi::class) 7 | internal fun SerialDescriptor.hoconKind(useArrayPolymorphism: Boolean): SerialKind = when (kind) { 8 | is PolymorphicKind -> { 9 | if (useArrayPolymorphism) StructureKind.LIST else StructureKind.MAP 10 | } 11 | else -> kind 12 | } 13 | 14 | @OptIn(ExperimentalSerializationApi::class) 15 | internal val SerialKind.listLike 16 | get() = this == StructureKind.LIST || this is PolymorphicKind 17 | 18 | @OptIn(ExperimentalSerializationApi::class) 19 | internal val SerialKind.objLike 20 | get() = this == StructureKind.CLASS || this == StructureKind.OBJECT 21 | -------------------------------------------------------------------------------- /formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/NamingConvention.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.hocon 2 | 3 | import kotlinx.serialization.* 4 | import kotlinx.serialization.descriptors.* 5 | 6 | private val NAMING_CONVENTION_REGEX by lazy { "[A-Z]".toRegex() } 7 | 8 | @OptIn(ExperimentalSerializationApi::class) 9 | internal fun SerialDescriptor.getConventionElementName(index: Int, useConfigNamingConvention: Boolean): String { 10 | val originalName = getElementName(index) 11 | return if (!useConfigNamingConvention) originalName 12 | else originalName.replace(NAMING_CONVENTION_REGEX) { "-${it.value.lowercase()}" } 13 | } 14 | -------------------------------------------------------------------------------- /formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/internal/SuppressAnimalSniffer.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.hocon.internal 2 | 3 | /** 4 | * Suppresses Animal Sniffer plugin errors for certain methods. 5 | * Such methods include references to Java 8 methods that are not 6 | * available in Android API, but can be desugared by R8. 7 | */ 8 | @Retention(AnnotationRetention.BINARY) 9 | @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) 10 | internal annotation class SuppressAnimalSniffer 11 | -------------------------------------------------------------------------------- /formats/hocon/src/mainModule/kotlin/module-info.java: -------------------------------------------------------------------------------- 1 | module kotlinx.serialization.hocon { 2 | requires transitive kotlin.stdlib; 3 | requires transitive kotlinx.serialization.core; 4 | requires transitive kotlin.stdlib.jdk8; 5 | requires transitive typesafe.config; 6 | 7 | exports kotlinx.serialization.hocon; 8 | } 9 | -------------------------------------------------------------------------------- /formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconTesting.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.hocon 2 | 3 | import com.typesafe.config.* 4 | import kotlinx.serialization.* 5 | import org.junit.Assert.assertEquals 6 | 7 | internal inline fun Hocon.assertStringFormAndRestored( 8 | expected: String, 9 | original: T, 10 | serializer: KSerializer, 11 | printResult: Boolean = false, 12 | ) { 13 | val expectedConfig = ConfigFactory.parseString(expected) 14 | val config = this.encodeToConfig(serializer, original) 15 | if (printResult) println("[Serialized form] $config") 16 | assertEquals(expectedConfig, config) 17 | val restored = this.decodeFromConfig(serializer, config) 18 | if (printResult) println("[Restored form] $restored") 19 | assertEquals(original, restored) 20 | } 21 | 22 | internal fun Config.assertContains(expected: String) { 23 | assertEquals(ConfigFactory.parseString(expected), this) 24 | } 25 | -------------------------------------------------------------------------------- /formats/json-io/api/kotlinx-serialization-json-io.api: -------------------------------------------------------------------------------- 1 | public final class kotlinx/serialization/json/io/IoStreamsKt { 2 | public static final fun decodeFromSource (Lkotlinx/serialization/json/Json;Lkotlinx/serialization/DeserializationStrategy;Lkotlinx/io/Source;)Ljava/lang/Object; 3 | public static final fun decodeSourceToSequence (Lkotlinx/serialization/json/Json;Lkotlinx/io/Source;Lkotlinx/serialization/DeserializationStrategy;Lkotlinx/serialization/json/DecodeSequenceMode;)Lkotlin/sequences/Sequence; 4 | public static synthetic fun decodeSourceToSequence$default (Lkotlinx/serialization/json/Json;Lkotlinx/io/Source;Lkotlinx/serialization/DeserializationStrategy;Lkotlinx/serialization/json/DecodeSequenceMode;ILjava/lang/Object;)Lkotlin/sequences/Sequence; 5 | public static final fun encodeToSink (Lkotlinx/serialization/json/Json;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;Lkotlinx/io/Sink;)V 6 | } 7 | 8 | -------------------------------------------------------------------------------- /formats/json-okio/api/kotlinx-serialization-json-okio.api: -------------------------------------------------------------------------------- 1 | public final class kotlinx/serialization/json/okio/OkioStreamsKt { 2 | public static final fun decodeBufferedSourceToSequence (Lkotlinx/serialization/json/Json;Lokio/BufferedSource;Lkotlinx/serialization/DeserializationStrategy;Lkotlinx/serialization/json/DecodeSequenceMode;)Lkotlin/sequences/Sequence; 3 | public static synthetic fun decodeBufferedSourceToSequence$default (Lkotlinx/serialization/json/Json;Lokio/BufferedSource;Lkotlinx/serialization/DeserializationStrategy;Lkotlinx/serialization/json/DecodeSequenceMode;ILjava/lang/Object;)Lkotlin/sequences/Sequence; 4 | public static final fun decodeFromBufferedSource (Lkotlinx/serialization/json/Json;Lkotlinx/serialization/DeserializationStrategy;Lokio/BufferedSource;)Ljava/lang/Object; 5 | public static final fun encodeToBufferedSink (Lkotlinx/serialization/json/Json;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;Lokio/BufferedSink;)V 6 | } 7 | 8 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/SerializableClasses.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization 6 | 7 | @Serializable 8 | data class IntData(val intV: Int) 9 | 10 | @Serializable 11 | data class StringData(val data: String) 12 | 13 | enum class SampleEnum { OptionA, OptionB, OptionC } 14 | 15 | @Serializable 16 | data class Box(val boxed: T) 17 | 18 | @Serializable 19 | sealed class SimpleSealed { 20 | @Serializable 21 | public data class SubSealedA(val s: String) : SimpleSealed() 22 | 23 | @Serializable 24 | public data class SubSealedB(val i: Int) : SimpleSealed() 25 | } 26 | 27 | @Serializable 28 | object SampleObject { 29 | val state: String = "myState" 30 | } 31 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/features/DurationTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.features 6 | 7 | import kotlinx.serialization.Serializable 8 | import kotlinx.serialization.json.JsonTestBase 9 | import kotlin.test.Test 10 | import kotlin.time.Duration 11 | import kotlin.time.DurationUnit 12 | import kotlin.time.toDuration 13 | 14 | class DurationTest : JsonTestBase() { 15 | @Serializable 16 | data class DurationHolder(val duration: Duration) 17 | @Test 18 | fun testDuration() { 19 | assertJsonFormAndRestored( 20 | DurationHolder.serializer(), 21 | DurationHolder(1000.toDuration(DurationUnit.SECONDS)), 22 | """{"duration":"PT16M40S"}""" 23 | ) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/features/EmojiTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.features 6 | 7 | import kotlinx.serialization.builtins.serializer 8 | import kotlinx.serialization.json.JsonTestBase 9 | import kotlin.test.Test 10 | 11 | 12 | class EmojiTest : JsonTestBase() { 13 | 14 | @Test 15 | fun testEmojiString() { 16 | assertJsonFormAndRestored( 17 | String.serializer(), 18 | "\uD83C\uDF34", 19 | "\"\uD83C\uDF34\"" 20 | ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedChild.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.features.sealed 2 | 3 | import kotlinx.serialization.SerialName 4 | import kotlinx.serialization.Serializable 5 | 6 | @Serializable 7 | @SerialName("first child") 8 | data class SealedChild(val j: Int) : SealedParent(1) 9 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedParent.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.features.sealed 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | sealed class SealedParent(val i: Int) 7 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonDefaultContextTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json 6 | 7 | import kotlin.test.* 8 | 9 | class JsonDefaultContextTest { 10 | 11 | @Test 12 | fun testRepeatedSerializer() { 13 | // #616 14 | val json = Json 15 | Json { serializersModule = json.serializersModule } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonImplicitNullsTest.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.json 2 | 3 | import kotlinx.serialization.* 4 | 5 | class JsonImplicitNullsTest: AbstractJsonImplicitNullsTest() { 6 | override fun Json.encode(value: T, serializer: KSerializer): String { 7 | return encodeToString(serializer, value) 8 | } 9 | 10 | override fun Json.decode(json: String, serializer: KSerializer): T { 11 | return decodeFromString(serializer, json) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonTreeImplicitNullsTest.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.json 2 | 3 | import kotlinx.serialization.KSerializer 4 | 5 | class JsonTreeImplicitNullsTest: AbstractJsonImplicitNullsTest() { 6 | override fun Json.encode(value: T, serializer: KSerializer): String { 7 | return encodeToJsonElement(serializer, value).toString() 8 | } 9 | 10 | override fun Json.decode(json: String, serializer: KSerializer): T { 11 | val jsonElement = parseToJsonElement(json) 12 | return decodeFromJsonElement(serializer, jsonElement) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/json/polymorphic/JsonDeserializePolymorphicTwiceTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.polymorphic 6 | 7 | import kotlinx.serialization.Serializable 8 | import kotlinx.serialization.json.* 9 | import kotlin.test.* 10 | 11 | class JsonDeserializePolymorphicTwiceTest { 12 | 13 | @Serializable 14 | sealed class Foo { 15 | @Serializable 16 | data class Bar(val a: Int) : Foo() 17 | } 18 | 19 | @Test 20 | fun testDeserializeTwice() { // #812 21 | val json = Json.encodeToJsonElement(Foo.serializer(), Foo.Bar(1)) 22 | assertEquals(Foo.Bar(1), Json.decodeFromJsonElement(Foo.serializer(), json)) 23 | assertEquals(Foo.Bar(1), Json.decodeFromJsonElement(Foo.serializer(), json)) 24 | } 25 | } -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/json/polymorphic/JsonPolymorphicClassDescriptorTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.polymorphic 6 | 7 | import kotlinx.serialization.json.* 8 | import kotlin.test.* 9 | 10 | class JsonPolymorphicClassDescriptorTest : JsonTestBase() { 11 | 12 | private val json = Json { 13 | classDiscriminator = "class" 14 | serializersModule = polymorphicTestModule 15 | encodeDefaults = true 16 | } 17 | 18 | @Test 19 | fun testPolymorphicProperties() = assertJsonFormAndRestored( 20 | InnerBox.serializer(), 21 | InnerBox(InnerImpl(42, "foo")), 22 | """{"base":{"class":"kotlinx.serialization.json.polymorphic.InnerImpl",""" + 23 | """"field":42,"str":"foo","nullable":null}}""", 24 | json 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/json/serializers/Primitives.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.serializers 6 | 7 | import kotlinx.serialization.* 8 | import kotlinx.serialization.json.* 9 | 10 | @Serializable 11 | data class JsonElementWrapper(val element: JsonElement) 12 | 13 | @Serializable 14 | data class JsonPrimitiveWrapper(val primitive: JsonPrimitive) 15 | 16 | @Serializable 17 | data class JsonNullWrapper(val element: JsonNull) 18 | 19 | @Serializable 20 | data class JsonObjectWrapper(val element: JsonObject) 21 | 22 | @Serializable 23 | data class JsonArrayWrapper(val array: JsonArray) -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/test/CurrentPlatform.common.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | enum class Platform { 8 | JVM, JS, NATIVE, WASM 9 | } 10 | 11 | public expect val currentPlatform: Platform 12 | 13 | public fun isJs(): Boolean = currentPlatform == Platform.JS 14 | public fun isJvm(): Boolean = currentPlatform == Platform.JVM 15 | public fun isNative(): Boolean = currentPlatform == Platform.NATIVE 16 | public fun isWasm(): Boolean = currentPlatform == Platform.WASM -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/test/JsonHelpers.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.test 2 | 3 | import kotlinx.serialization.DeserializationStrategy 4 | import kotlinx.serialization.SerializationStrategy 5 | import kotlinx.serialization.json.Json 6 | 7 | public expect fun Json.encodeViaStream(serializer: SerializationStrategy, value: T): String 8 | 9 | public expect fun Json.decodeViaStream(serializer: DeserializationStrategy, input: String): T 10 | -------------------------------------------------------------------------------- /formats/json-tests/commonTest/src/kotlinx/serialization/test/TestId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | import kotlinx.serialization.* 8 | import kotlinx.serialization.descriptors.* 9 | 10 | @SerialInfo 11 | @Target(AnnotationTarget.PROPERTY) 12 | annotation class Id(val id: Int) 13 | -------------------------------------------------------------------------------- /formats/json-tests/jsTest/src/kotlinx/serialization/json/JsonDynamicImplicitNullsTest.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.json 2 | 3 | import kotlinx.serialization.KSerializer 4 | 5 | class JsonDynamicImplicitNullsTest : AbstractJsonImplicitNullsTest() { 6 | override fun Json.encode(value: T, serializer: KSerializer): String { 7 | return JSON.stringify(encodeToDynamic(serializer, value)) 8 | } 9 | 10 | override fun Json.decode(json: String, serializer: KSerializer): T { 11 | val x: dynamic = JSON.parse(json) 12 | return decodeFromDynamic(serializer, x) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /formats/json-tests/jsTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | public actual val currentPlatform: Platform = Platform.JS 8 | -------------------------------------------------------------------------------- /formats/json-tests/jsTest/src/kotlinx/serialization/test/JsonHelpers.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.test 2 | 3 | import kotlinx.serialization.DeserializationStrategy 4 | import kotlinx.serialization.SerializationStrategy 5 | import kotlinx.serialization.json.Json 6 | 7 | actual fun Json.encodeViaStream( 8 | serializer: SerializationStrategy, 9 | value: T 10 | ): String { 11 | TODO("supported on JVM only") 12 | } 13 | 14 | actual fun Json.decodeViaStream( 15 | serializer: DeserializationStrategy, 16 | input: String 17 | ): T { 18 | TODO("supported on JVM only") 19 | } 20 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/class_loaders/classes/example/Foo$$serializer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/class_loaders/classes/example/Foo$$serializer.class -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/class_loaders/classes/example/Foo$Companion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/class_loaders/classes/example/Foo$Companion.class -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/class_loaders/classes/example/Foo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/class_loaders/classes/example/Foo.class -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/listing.txt: -------------------------------------------------------------------------------- 1 | number_1.0.json 2 | number_1.000000000000000005.json 3 | number_1000000000000000.json 4 | number_10000000000000000999.json 5 | number_1e-999.json 6 | number_1e6.json 7 | object_key_nfc_nfd.json 8 | object_key_nfd_nfc.json 9 | object_same_key_different_values.json 10 | object_same_key_same_value.json 11 | object_same_key_unclear_values.json 12 | string_1_escaped_invalid_codepoint.json 13 | string_1_invalid_codepoint.json 14 | string_2_escaped_invalid_codepoints.json 15 | string_2_invalid_codepoints.json 16 | string_3_escaped_invalid_codepoints.json 17 | string_3_invalid_codepoints.json 18 | string_with_escaped_NULL.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/number_1.0.json: -------------------------------------------------------------------------------- 1 | [1.0] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/number_1.000000000000000005.json: -------------------------------------------------------------------------------- 1 | [1.000000000000000005] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/number_1000000000000000.json: -------------------------------------------------------------------------------- 1 | [1000000000000000] 2 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/number_10000000000000000999.json: -------------------------------------------------------------------------------- 1 | [10000000000000000999] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/number_1e-999.json: -------------------------------------------------------------------------------- 1 | [1E-999] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/number_1e6.json: -------------------------------------------------------------------------------- 1 | [1E6] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/object_key_nfc_nfd.json: -------------------------------------------------------------------------------- 1 | {"é":"NFC","é":"NFD"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/object_key_nfd_nfc.json: -------------------------------------------------------------------------------- 1 | {"é":"NFD","é":"NFC"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/object_same_key_different_values.json: -------------------------------------------------------------------------------- 1 | {"a":1,"a":2} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/object_same_key_same_value.json: -------------------------------------------------------------------------------- 1 | {"a":1,"a":1} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/object_same_key_unclear_values.json: -------------------------------------------------------------------------------- 1 | {"a":0, "a":-0} 2 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/string_1_escaped_invalid_codepoint.json: -------------------------------------------------------------------------------- 1 | ["\uD800"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/string_1_invalid_codepoint.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/corner_cases/string_1_invalid_codepoint.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/string_2_escaped_invalid_codepoints.json: -------------------------------------------------------------------------------- 1 | ["\uD800\uD800"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/string_2_invalid_codepoints.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/corner_cases/string_2_invalid_codepoints.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/string_3_escaped_invalid_codepoints.json: -------------------------------------------------------------------------------- 1 | ["\uD800\uD800\uD800"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/string_3_invalid_codepoints.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/corner_cases/string_3_invalid_codepoints.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corner_cases/string_with_escaped_NULL.json: -------------------------------------------------------------------------------- 1 | ["A\u0000B"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/corpus.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/corpus.zip -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/listing_comments.txt: -------------------------------------------------------------------------------- 1 | // Non-spec inputs that we accept with allowComments = true setting: 2 | n_object_trailing_comment.json 3 | n_object_trailing_comment_slash_open.json 4 | n_structure_object_with_comment.json 5 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_1_true_without_comma.json: -------------------------------------------------------------------------------- 1 | [1 true] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_a_invalid_utf8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/spec_cases/n_array_a_invalid_utf8.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_colon_instead_of_comma.json: -------------------------------------------------------------------------------- 1 | ["": 1] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_comma_after_close.json: -------------------------------------------------------------------------------- 1 | [""], -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_comma_and_number.json: -------------------------------------------------------------------------------- 1 | [,1] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_double_comma.json: -------------------------------------------------------------------------------- 1 | [1,,2] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_double_extra_comma.json: -------------------------------------------------------------------------------- 1 | ["x",,] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_extra_close.json: -------------------------------------------------------------------------------- 1 | ["x"]] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_extra_comma.json: -------------------------------------------------------------------------------- 1 | ["",] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_incomplete.json: -------------------------------------------------------------------------------- 1 | ["x" -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_incomplete_invalid_value.json: -------------------------------------------------------------------------------- 1 | [x -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_inner_array_no_comma.json: -------------------------------------------------------------------------------- 1 | [3[4]] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_invalid_utf8.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/spec_cases/n_array_invalid_utf8.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_items_separated_by_semicolon.json: -------------------------------------------------------------------------------- 1 | [1:2] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_just_comma.json: -------------------------------------------------------------------------------- 1 | [,] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_just_minus.json: -------------------------------------------------------------------------------- 1 | [-] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_missing_value.json: -------------------------------------------------------------------------------- 1 | [ , ""] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_newlines_unclosed.json: -------------------------------------------------------------------------------- 1 | ["a", 2 | 4 3 | ,1, -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_number_and_comma.json: -------------------------------------------------------------------------------- 1 | [1,] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_number_and_several_commas.json: -------------------------------------------------------------------------------- 1 | [1,,] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_spaces_vertical_tab_formfeed.json: -------------------------------------------------------------------------------- 1 | [" a"\f] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_star_inside.json: -------------------------------------------------------------------------------- 1 | [*] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_unclosed.json: -------------------------------------------------------------------------------- 1 | ["" -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_unclosed_trailing_comma.json: -------------------------------------------------------------------------------- 1 | [1, -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_unclosed_with_new_lines.json: -------------------------------------------------------------------------------- 1 | [1, 2 | 1 3 | ,1 -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_array_unclosed_with_object_inside.json: -------------------------------------------------------------------------------- 1 | [{} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_incomplete_false.json: -------------------------------------------------------------------------------- 1 | [fals] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_incomplete_null.json: -------------------------------------------------------------------------------- 1 | [nul] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_incomplete_true.json: -------------------------------------------------------------------------------- 1 | [tru] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_multidigit_number_then_00.json: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_bad_value.json: -------------------------------------------------------------------------------- 1 | ["x", truth] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_bracket_key.json: -------------------------------------------------------------------------------- 1 | {[: "x"} 2 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_comma_instead_of_colon.json: -------------------------------------------------------------------------------- 1 | {"x", null} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_double_colon.json: -------------------------------------------------------------------------------- 1 | {"x"::"b"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_emoji.json: -------------------------------------------------------------------------------- 1 | {🇨🇭} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_garbage_at_end.json: -------------------------------------------------------------------------------- 1 | {"a":"a" 123} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_key_with_single_quotes.json: -------------------------------------------------------------------------------- 1 | {key: 'value'} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_lone_continuation_byte_in_key_and_trailing_comma.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/spec_cases/n_object_lone_continuation_byte_in_key_and_trailing_comma.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_missing_colon.json: -------------------------------------------------------------------------------- 1 | {"a" b} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_missing_key.json: -------------------------------------------------------------------------------- 1 | {:"b"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_missing_semicolon.json: -------------------------------------------------------------------------------- 1 | {"a" "b"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_missing_value.json: -------------------------------------------------------------------------------- 1 | {"a": -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_no-colon.json: -------------------------------------------------------------------------------- 1 | {"a" -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_non_string_key.json: -------------------------------------------------------------------------------- 1 | {1:1} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_non_string_key_but_huge_number_instead.json: -------------------------------------------------------------------------------- 1 | {9999E9999:1} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_repeated_null_null.json: -------------------------------------------------------------------------------- 1 | {null:null,null:null} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_several_trailing_commas.json: -------------------------------------------------------------------------------- 1 | {"id":0,,,,,} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_single_quote.json: -------------------------------------------------------------------------------- 1 | {'a':0} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_trailing_comma.json: -------------------------------------------------------------------------------- 1 | {"id":0,} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_trailing_comment.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}/**/ -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_trailing_comment_open.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}/**// -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_trailing_comment_slash_open.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}// -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_trailing_comment_slash_open_incomplete.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}/ -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_two_commas_in_a_row.json: -------------------------------------------------------------------------------- 1 | {"a":"b",,"c":"d"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_unquoted_key.json: -------------------------------------------------------------------------------- 1 | {a: "b"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_unterminated-value.json: -------------------------------------------------------------------------------- 1 | {"a":"a -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_with_single_string.json: -------------------------------------------------------------------------------- 1 | { "foo" : "bar", "a" } -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_object_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}# -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_single_space.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_1_surrogate_then_escape.json: -------------------------------------------------------------------------------- 1 | ["\uD800\"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_1_surrogate_then_escape_u.json: -------------------------------------------------------------------------------- 1 | ["\uD800\u"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_1_surrogate_then_escape_u1.json: -------------------------------------------------------------------------------- 1 | ["\uD800\u1"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_1_surrogate_then_escape_u1x.json: -------------------------------------------------------------------------------- 1 | ["\uD800\u1x"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_accentuated_char_no_quotes.json: -------------------------------------------------------------------------------- 1 | [é] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_backslash_00.json: -------------------------------------------------------------------------------- 1 | ["\"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_escape_x.json: -------------------------------------------------------------------------------- 1 | ["\x00"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_escaped_backslash_bad.json: -------------------------------------------------------------------------------- 1 | ["\\\"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_escaped_ctrl_char_tab.json: -------------------------------------------------------------------------------- 1 | ["\ "] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_escaped_emoji.json: -------------------------------------------------------------------------------- 1 | ["\🌀"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_incomplete_escape.json: -------------------------------------------------------------------------------- 1 | ["\"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_incomplete_escaped_character.json: -------------------------------------------------------------------------------- 1 | ["\u00A"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_incomplete_surrogate.json: -------------------------------------------------------------------------------- 1 | ["\uD834\uDd"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_incomplete_surrogate_escape_invalid.json: -------------------------------------------------------------------------------- 1 | ["\uD800\uD800\x"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_invalid-utf-8-in-escape.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/spec_cases/n_string_invalid-utf-8-in-escape.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_invalid_backslash_esc.json: -------------------------------------------------------------------------------- 1 | ["\a"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_invalid_unicode_escape.json: -------------------------------------------------------------------------------- 1 | ["\uqqqq"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_invalid_utf8_after_escape.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/spec_cases/n_string_invalid_utf8_after_escape.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_leading_uescaped_thinspace.json: -------------------------------------------------------------------------------- 1 | [\u0020"asd"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_no_quotes_with_bad_escape.json: -------------------------------------------------------------------------------- 1 | [\n] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_single_doublequote.json: -------------------------------------------------------------------------------- 1 | " -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_single_quote.json: -------------------------------------------------------------------------------- 1 | ['single quote'] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_single_string_no_double_quotes.json: -------------------------------------------------------------------------------- 1 | abc -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_start_escape_unclosed.json: -------------------------------------------------------------------------------- 1 | ["\ -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_unescaped_crtl_char.json: -------------------------------------------------------------------------------- 1 | ["aa"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_unescaped_newline.json: -------------------------------------------------------------------------------- 1 | ["new 2 | line"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_unescaped_tab.json: -------------------------------------------------------------------------------- 1 | [" "] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_unicode_CapitalU.json: -------------------------------------------------------------------------------- 1 | "\UA66D" -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_string_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | ""x -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_U+2060_word_joined.json: -------------------------------------------------------------------------------- 1 | [⁠] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_UTF8_BOM_no_data.json: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_angle_bracket_..json: -------------------------------------------------------------------------------- 1 | <.> -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_angle_bracket_null.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_array_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | [1]x -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_array_with_extra_array_close.json: -------------------------------------------------------------------------------- 1 | [1]] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_array_with_unclosed_string.json: -------------------------------------------------------------------------------- 1 | ["asd] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_ascii-unicode-identifier.json: -------------------------------------------------------------------------------- 1 | aå -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_capitalized_True.json: -------------------------------------------------------------------------------- 1 | [True] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_close_unopened_array.json: -------------------------------------------------------------------------------- 1 | 1] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_comma_instead_of_closing_brace.json: -------------------------------------------------------------------------------- 1 | {"x": true, -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_double_array.json: -------------------------------------------------------------------------------- 1 | [][] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_end_array.json: -------------------------------------------------------------------------------- 1 | ] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_incomplete_UTF8_BOM.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/spec_cases/n_structure_incomplete_UTF8_BOM.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_lone-invalid-utf-8.json: -------------------------------------------------------------------------------- 1 | � -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_lone-open-bracket.json: -------------------------------------------------------------------------------- 1 | [ -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_no_data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/formats/json-tests/jvmTest/resources/spec_cases/n_structure_no_data.json -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_null-byte-outside-string.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_number_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | 2@ -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_object_followed_by_closing_object.json: -------------------------------------------------------------------------------- 1 | {}} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_object_unclosed_no_value.json: -------------------------------------------------------------------------------- 1 | {"": -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_object_with_comment.json: -------------------------------------------------------------------------------- 1 | {"a":/*comment*/"b"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_object_with_trailing_garbage.json: -------------------------------------------------------------------------------- 1 | {"a": true} "x" -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_array_apostrophe.json: -------------------------------------------------------------------------------- 1 | [' -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_array_comma.json: -------------------------------------------------------------------------------- 1 | [, -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_array_open_object.json: -------------------------------------------------------------------------------- 1 | [{ -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_array_open_string.json: -------------------------------------------------------------------------------- 1 | ["a -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_array_string.json: -------------------------------------------------------------------------------- 1 | ["a" -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_object.json: -------------------------------------------------------------------------------- 1 | { -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_object_close_array.json: -------------------------------------------------------------------------------- 1 | {] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_object_comma.json: -------------------------------------------------------------------------------- 1 | {, -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_object_open_array.json: -------------------------------------------------------------------------------- 1 | {[ -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_object_open_string.json: -------------------------------------------------------------------------------- 1 | {"a -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_object_string_with_apostrophes.json: -------------------------------------------------------------------------------- 1 | {'a' -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_open_open.json: -------------------------------------------------------------------------------- 1 | ["\{["\{["\{["\{ -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_single_star.json: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_trailing_#.json: -------------------------------------------------------------------------------- 1 | {"a":"b"}#{} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_uescaped_LF_before_string.json: -------------------------------------------------------------------------------- 1 | [\u000A""] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_unclosed_array.json: -------------------------------------------------------------------------------- 1 | [1 -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_unclosed_array_partial_null.json: -------------------------------------------------------------------------------- 1 | [ false, nul -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_unclosed_array_unfinished_false.json: -------------------------------------------------------------------------------- 1 | [ true, fals -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_unclosed_array_unfinished_true.json: -------------------------------------------------------------------------------- 1 | [ false, tru -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_unclosed_object.json: -------------------------------------------------------------------------------- 1 | {"asd":"asd" -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_unicode-identifier.json: -------------------------------------------------------------------------------- 1 | å -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_whitespace_U+2060_word_joiner.json: -------------------------------------------------------------------------------- 1 | [⁠] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/n_structure_whitespace_formfeed.json: -------------------------------------------------------------------------------- 1 | [ ] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_arraysWithSpaces.json: -------------------------------------------------------------------------------- 1 | [[] ] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_empty-string.json: -------------------------------------------------------------------------------- 1 | [""] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_empty.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_ending_with_newline.json: -------------------------------------------------------------------------------- 1 | ["a"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_false.json: -------------------------------------------------------------------------------- 1 | [false] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_heterogeneous.json: -------------------------------------------------------------------------------- 1 | [null, 1, "1", {}] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_null.json: -------------------------------------------------------------------------------- 1 | [null] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_with_1_and_newline.json: -------------------------------------------------------------------------------- 1 | [1 2 | ] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_with_leading_space.json: -------------------------------------------------------------------------------- 1 | [1] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_with_several_null.json: -------------------------------------------------------------------------------- 1 | [1,null,null,null,2] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_array_with_trailing_space.json: -------------------------------------------------------------------------------- 1 | [2] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number.json: -------------------------------------------------------------------------------- 1 | [123e65] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_0e+1.json: -------------------------------------------------------------------------------- 1 | [0e+1] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_0e1.json: -------------------------------------------------------------------------------- 1 | [0e1] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_after_space.json: -------------------------------------------------------------------------------- 1 | [ 4] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_double_close_to_zero.json: -------------------------------------------------------------------------------- 1 | [-0.000000000000000000000000000000000000000000000000000000000000000000000000000001] 2 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_int_with_exp.json: -------------------------------------------------------------------------------- 1 | [20e1] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_minus_zero.json: -------------------------------------------------------------------------------- 1 | [-0] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_negative_int.json: -------------------------------------------------------------------------------- 1 | [-123] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_negative_one.json: -------------------------------------------------------------------------------- 1 | [-1] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_negative_zero.json: -------------------------------------------------------------------------------- 1 | [-0] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_real_capital_e.json: -------------------------------------------------------------------------------- 1 | [1E22] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_real_capital_e_neg_exp.json: -------------------------------------------------------------------------------- 1 | [1E-2] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_real_capital_e_pos_exp.json: -------------------------------------------------------------------------------- 1 | [1E+2] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_real_exponent.json: -------------------------------------------------------------------------------- 1 | [123e45] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_real_fraction_exponent.json: -------------------------------------------------------------------------------- 1 | [123.456e78] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_real_neg_exp.json: -------------------------------------------------------------------------------- 1 | [1e-2] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_real_pos_exponent.json: -------------------------------------------------------------------------------- 1 | [1e+2] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_simple_int.json: -------------------------------------------------------------------------------- 1 | [123] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_number_simple_real.json: -------------------------------------------------------------------------------- 1 | [123.456789] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object.json: -------------------------------------------------------------------------------- 1 | {"asd":"sdf", "dfg":"fgh"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_basic.json: -------------------------------------------------------------------------------- 1 | {"asd":"sdf"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_duplicated_key.json: -------------------------------------------------------------------------------- 1 | {"a":"b","a":"c"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_duplicated_key_and_value.json: -------------------------------------------------------------------------------- 1 | {"a":"b","a":"b"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_empty.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_empty_key.json: -------------------------------------------------------------------------------- 1 | {"":0} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_escaped_null_in_key.json: -------------------------------------------------------------------------------- 1 | {"foo\u0000bar": 42} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_extreme_numbers.json: -------------------------------------------------------------------------------- 1 | { "min": -1.0e+28, "max": 1.0e+28 } -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_long_strings.json: -------------------------------------------------------------------------------- 1 | {"x":[{"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}], "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_simple.json: -------------------------------------------------------------------------------- 1 | {"a":[]} -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_string_unicode.json: -------------------------------------------------------------------------------- 1 | {"title":"\u041f\u043e\u043b\u0442\u043e\u0440\u0430 \u0417\u0435\u043c\u043b\u0435\u043a\u043e\u043f\u0430" } -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_object_with_newlines.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": "b" 3 | } -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_1_2_3_bytes_UTF-8_sequences.json: -------------------------------------------------------------------------------- 1 | ["\u0060\u012a\u12AB"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_accepted_surrogate_pair.json: -------------------------------------------------------------------------------- 1 | ["\uD801\udc37"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_accepted_surrogate_pairs.json: -------------------------------------------------------------------------------- 1 | ["\ud83d\ude39\ud83d\udc8d"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_allowed_escapes.json: -------------------------------------------------------------------------------- 1 | ["\"\\\/\b\f\n\r\t"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_backslash_and_u_escaped_zero.json: -------------------------------------------------------------------------------- 1 | ["\\u0000"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_backslash_doublequotes.json: -------------------------------------------------------------------------------- 1 | ["\""] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_comments.json: -------------------------------------------------------------------------------- 1 | ["a/*b*/c/*d//e"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_double_escape_a.json: -------------------------------------------------------------------------------- 1 | ["\\a"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_double_escape_n.json: -------------------------------------------------------------------------------- 1 | ["\\n"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_escaped_control_character.json: -------------------------------------------------------------------------------- 1 | ["\u0012"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_escaped_noncharacter.json: -------------------------------------------------------------------------------- 1 | ["\uFFFF"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_in_array.json: -------------------------------------------------------------------------------- 1 | ["asd"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_in_array_with_leading_space.json: -------------------------------------------------------------------------------- 1 | [ "asd"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_last_surrogates_1_and_2.json: -------------------------------------------------------------------------------- 1 | ["\uDBFF\uDFFF"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_nbsp_uescaped.json: -------------------------------------------------------------------------------- 1 | ["new\u00A0line"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_nonCharacterInUTF-8_U+10FFFF.json: -------------------------------------------------------------------------------- 1 | ["􏿿"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_nonCharacterInUTF-8_U+FFFF.json: -------------------------------------------------------------------------------- 1 | ["￿"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_null_escape.json: -------------------------------------------------------------------------------- 1 | ["\u0000"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_one-byte-utf-8.json: -------------------------------------------------------------------------------- 1 | ["\u002c"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_pi.json: -------------------------------------------------------------------------------- 1 | ["π"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_reservedCharacterInUTF-8_U+1BFFF.json: -------------------------------------------------------------------------------- 1 | ["𛿿"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_simple_ascii.json: -------------------------------------------------------------------------------- 1 | ["asd "] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_space.json: -------------------------------------------------------------------------------- 1 | " " -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json: -------------------------------------------------------------------------------- 1 | ["\uD834\uDd1e"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_three-byte-utf-8.json: -------------------------------------------------------------------------------- 1 | ["\u0821"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_two-byte-utf-8.json: -------------------------------------------------------------------------------- 1 | ["\u0123"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_u+2028_line_sep.json: -------------------------------------------------------------------------------- 1 | ["
"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_u+2029_par_sep.json: -------------------------------------------------------------------------------- 1 | ["
"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_uEscape.json: -------------------------------------------------------------------------------- 1 | ["\u0061\u30af\u30EA\u30b9"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_uescaped_newline.json: -------------------------------------------------------------------------------- 1 | ["new\u000Aline"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unescaped_char_delete.json: -------------------------------------------------------------------------------- 1 | [""] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicode.json: -------------------------------------------------------------------------------- 1 | ["\uA66D"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicodeEscapedBackslash.json: -------------------------------------------------------------------------------- 1 | ["\u005C"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicode_2.json: -------------------------------------------------------------------------------- 1 | ["⍂㈴⍂"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicode_U+10FFFE_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uDBFF\uDFFE"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicode_U+1FFFE_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uD83F\uDFFE"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json: -------------------------------------------------------------------------------- 1 | ["\u200B"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicode_U+2064_invisible_plus.json: -------------------------------------------------------------------------------- 1 | ["\u2064"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicode_U+FDD0_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uFDD0"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicode_U+FFFE_nonchar.json: -------------------------------------------------------------------------------- 1 | ["\uFFFE"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_unicode_escaped_double_quote.json: -------------------------------------------------------------------------------- 1 | ["\u0022"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_utf8.json: -------------------------------------------------------------------------------- 1 | ["€𝄞"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_string_with_del_character.json: -------------------------------------------------------------------------------- 1 | ["aa"] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_lonely_false.json: -------------------------------------------------------------------------------- 1 | false -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_lonely_int.json: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_lonely_negative_real.json: -------------------------------------------------------------------------------- 1 | -0.1 -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_lonely_null.json: -------------------------------------------------------------------------------- 1 | null -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_lonely_string.json: -------------------------------------------------------------------------------- 1 | "asd" -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_lonely_true.json: -------------------------------------------------------------------------------- 1 | true -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_string_empty.json: -------------------------------------------------------------------------------- 1 | "" -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_trailing_newline.json: -------------------------------------------------------------------------------- 1 | ["a"] 2 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_true_in_array.json: -------------------------------------------------------------------------------- 1 | [true] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/resources/spec_cases/y_structure_whitespace_array.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | 8 | public actual val currentPlatform: Platform = Platform.JVM 9 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/src/kotlinx/serialization/test/JsonHelpers.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.test 2 | 3 | import kotlinx.serialization.DeserializationStrategy 4 | import kotlinx.serialization.SerializationStrategy 5 | import kotlinx.serialization.json.* 6 | import java.io.ByteArrayOutputStream 7 | 8 | actual fun Json.encodeViaStream( 9 | serializer: SerializationStrategy, 10 | value: T 11 | ): String { 12 | val output = ByteArrayOutputStream() 13 | encodeToStream(serializer, value, output) 14 | return output.toString(Charsets.UTF_8.name()) 15 | } 16 | 17 | actual fun Json.decodeViaStream( 18 | serializer: DeserializationStrategy, 19 | input: String 20 | ): T = decodeFromStream(serializer, input.byteInputStream()) 21 | -------------------------------------------------------------------------------- /formats/json-tests/jvmTest/src/kotlinx/serialization/test/TypeToken.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | import java.lang.reflect.* 8 | 9 | 10 | @PublishedApi 11 | internal open class TypeBase 12 | 13 | public inline fun typeTokenOf(): Type { 14 | val base = object : TypeBase() {} 15 | val superType = base::class.java.genericSuperclass!! 16 | return (superType as ParameterizedType).actualTypeArguments.first()!! 17 | } 18 | -------------------------------------------------------------------------------- /formats/json-tests/nativeTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | 8 | public actual val currentPlatform: Platform = Platform.NATIVE 9 | -------------------------------------------------------------------------------- /formats/json-tests/nativeTest/src/kotlinx/serialization/test/JsonHelpers.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.test 2 | 3 | import kotlinx.serialization.DeserializationStrategy 4 | import kotlinx.serialization.SerializationStrategy 5 | import kotlinx.serialization.json.Json 6 | 7 | actual fun Json.encodeViaStream( 8 | serializer: SerializationStrategy, 9 | value: T 10 | ): String { 11 | TODO("supported on JVM only") 12 | } 13 | 14 | actual fun Json.decodeViaStream( 15 | serializer: DeserializationStrategy, 16 | input: String 17 | ): T { 18 | TODO("supported on JVM only") 19 | } 20 | -------------------------------------------------------------------------------- /formats/json-tests/wasmTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | public actual val currentPlatform: Platform = Platform.WASM -------------------------------------------------------------------------------- /formats/json-tests/wasmTest/src/kotlinx/serialization/test/JsonHelpers.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.test 2 | 3 | import kotlinx.serialization.DeserializationStrategy 4 | import kotlinx.serialization.SerializationStrategy 5 | import kotlinx.serialization.json.Json 6 | 7 | actual fun Json.encodeViaStream( 8 | serializer: SerializationStrategy, 9 | value: T 10 | ): String { 11 | TODO("supported on JVM only") 12 | } 13 | 14 | actual fun Json.decodeViaStream( 15 | serializer: DeserializationStrategy, 16 | input: String 17 | ): T { 18 | TODO("supported on JVM only") 19 | } -------------------------------------------------------------------------------- /formats/json/commonMain/src/kotlinx/serialization/json/internal/CharArrayPool.common.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | package kotlinx.serialization.json.internal 5 | 6 | internal expect object CharArrayPoolBatchSize { 7 | fun take(): CharArray 8 | fun release(array: CharArray) 9 | } 10 | -------------------------------------------------------------------------------- /formats/json/commonMain/src/kotlinx/serialization/json/internal/JsonToStringWriter.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.json.internal 2 | 3 | internal expect class JsonToStringWriter constructor() : InternalJsonWriter { 4 | override fun writeChar(char: Char) 5 | override fun writeLong(value: Long) 6 | override fun write(text: String) 7 | override fun writeQuoted(text: String) 8 | override fun toString(): String 9 | override fun release() 10 | } 11 | -------------------------------------------------------------------------------- /formats/json/commonMain/src/kotlinx/serialization/json/internal/SuppressAnimalSniffer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.internal 6 | 7 | /** 8 | * Suppresses Animal Sniffer plugin errors for certain methods. 9 | * Such methods include references to Java 8 methods that are not 10 | * available in Android API, but can be desugared by R8. 11 | */ 12 | @Retention(AnnotationRetention.BINARY) 13 | @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) 14 | internal annotation class SuppressAnimalSniffer 15 | -------------------------------------------------------------------------------- /formats/json/jsWasmMain/src/kotlinx/serialization/json/JsonSchemaCache.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json 6 | 7 | import kotlinx.serialization.json.internal.* 8 | 9 | @Suppress("DEPRECATION_ERROR") 10 | internal actual val Json.schemaCache: DescriptorSchemaCache get() = this._schemaCache 11 | -------------------------------------------------------------------------------- /formats/json/jsWasmMain/src/kotlinx/serialization/json/internal/CharArrayPool.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | package kotlinx.serialization.json.internal 5 | 6 | 7 | internal actual object CharArrayPoolBatchSize { 8 | 9 | actual fun take(): CharArray = CharArray(BATCH_SIZE) 10 | 11 | actual fun release(array: CharArray) = Unit 12 | } 13 | -------------------------------------------------------------------------------- /formats/json/jsWasmMain/src/kotlinx/serialization/json/internal/FormatLanguageJsWasm.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.internal; 6 | 7 | import kotlinx.serialization.InternalSerializationApi 8 | 9 | @InternalSerializationApi 10 | @Retention(AnnotationRetention.BINARY) 11 | @Target( 12 | AnnotationTarget.FUNCTION, 13 | AnnotationTarget.PROPERTY_GETTER, 14 | AnnotationTarget.PROPERTY_SETTER, 15 | AnnotationTarget.FIELD, 16 | AnnotationTarget.VALUE_PARAMETER, 17 | AnnotationTarget.LOCAL_VARIABLE, 18 | AnnotationTarget.ANNOTATION_CLASS 19 | ) 20 | public actual annotation class FormatLanguage( 21 | public actual val value: String, 22 | // default parameters are not used due to https://youtrack.jetbrains.com/issue/KT-25946/ 23 | public actual val prefix: String, 24 | public actual val suffix: String, 25 | ) 26 | -------------------------------------------------------------------------------- /formats/json/jsWasmMain/src/kotlinx/serialization/json/internal/JsonToStringWriterJsWasm.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.json.internal 2 | 3 | internal actual open class JsonToStringWriter actual constructor(): InternalJsonWriter { 4 | private val sb = StringBuilder(128) 5 | 6 | actual override fun writeLong(value: Long) { 7 | sb.append(value) 8 | } 9 | 10 | actual override fun writeChar(char: Char) { 11 | sb.append(char) 12 | } 13 | 14 | actual override fun write(text: String) { 15 | sb.append(text) 16 | } 17 | 18 | actual override fun writeQuoted(text: String) { 19 | sb.printQuoted(text) 20 | } 21 | 22 | actual override fun release() { 23 | sb.clear() 24 | } 25 | 26 | actual override fun toString(): String { 27 | return sb.toString() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /formats/json/jsWasmMain/src/kotlinx/serialization/json/internal/createMapForCache.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.internal 6 | 7 | /** 8 | * Creates a ConcurrentHashMap on JVM and regular HashMap on other platforms. 9 | * To make actual use of cache in Kotlin/Native, mark a top-level object with this map 10 | * as a @[ThreadLocal]. 11 | */ 12 | internal actual fun createMapForCache(initialCapacity: Int): MutableMap = HashMap(initialCapacity) 13 | -------------------------------------------------------------------------------- /formats/json/jvmMain/src/kotlinx/serialization/json/JsonSchemaCache.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json 6 | 7 | import kotlinx.serialization.json.internal.* 8 | 9 | @Suppress("DEPRECATION_ERROR") 10 | internal actual val Json.schemaCache: DescriptorSchemaCache get() = this._schemaCache 11 | -------------------------------------------------------------------------------- /formats/json/jvmMain/src/kotlinx/serialization/json/internal/FormatLanguage.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.internal; 6 | 7 | import kotlinx.serialization.InternalSerializationApi 8 | 9 | @InternalSerializationApi 10 | public actual typealias FormatLanguage = org.intellij.lang.annotations.Language -------------------------------------------------------------------------------- /formats/json/jvmMain/src/kotlinx/serialization/json/internal/createMapForCache.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.internal 6 | 7 | import java.util.concurrent.* 8 | 9 | /** 10 | * Creates a ConcurrentHashMap on JVM and regular HashMap on other platforms. 11 | * To make actual use of cache in Kotlin/Native, mark a top-level object with this map 12 | * as a @[ThreadLocal]. 13 | */ 14 | internal actual fun createMapForCache(initialCapacity: Int): MutableMap = 15 | ConcurrentHashMap(initialCapacity) 16 | -------------------------------------------------------------------------------- /formats/json/jvmMainModule/src/module-info.java: -------------------------------------------------------------------------------- 1 | module kotlinx.serialization.json { 2 | requires transitive kotlin.stdlib; 3 | requires transitive kotlinx.serialization.core; 4 | 5 | exports kotlinx.serialization.json; 6 | } 7 | -------------------------------------------------------------------------------- /formats/json/nativeMain/src/kotlinx/serialization/json/internal/CharArrayPool.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | package kotlinx.serialization.json.internal 5 | 6 | internal actual object CharArrayPoolBatchSize { 7 | actual fun take(): CharArray = CharArray(BATCH_SIZE) 8 | actual fun release(array: CharArray) = Unit 9 | } 10 | -------------------------------------------------------------------------------- /formats/json/nativeMain/src/kotlinx/serialization/json/internal/FormatLanguage.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.internal; 6 | 7 | import kotlinx.serialization.InternalSerializationApi 8 | 9 | @InternalSerializationApi 10 | @Retention(AnnotationRetention.BINARY) 11 | @Target( 12 | AnnotationTarget.FUNCTION, 13 | AnnotationTarget.PROPERTY_GETTER, 14 | AnnotationTarget.PROPERTY_SETTER, 15 | AnnotationTarget.FIELD, 16 | AnnotationTarget.VALUE_PARAMETER, 17 | AnnotationTarget.LOCAL_VARIABLE, 18 | AnnotationTarget.ANNOTATION_CLASS 19 | ) 20 | public actual annotation class FormatLanguage( 21 | public actual val value: String, 22 | // default parameters are not used due to https://youtrack.jetbrains.com/issue/KT-25946/ 23 | public actual val prefix: String, 24 | public actual val suffix: String, 25 | ) -------------------------------------------------------------------------------- /formats/json/nativeMain/src/kotlinx/serialization/json/internal/JsonToStringWriter.kt: -------------------------------------------------------------------------------- 1 | package kotlinx.serialization.json.internal 2 | 3 | internal actual open class JsonToStringWriter actual constructor(): InternalJsonWriter { 4 | private val sb = StringBuilder(128) 5 | 6 | actual override fun writeLong(value: Long) { 7 | sb.append(value) 8 | } 9 | 10 | actual override fun writeChar(char: Char) { 11 | sb.append(char) 12 | } 13 | 14 | actual override fun write(text: String) { 15 | sb.append(text) 16 | } 17 | 18 | actual override fun writeQuoted(text: String) { 19 | sb.printQuoted(text) 20 | } 21 | 22 | actual override fun release() { 23 | // nothing to flush 24 | } 25 | 26 | actual override fun toString(): String { 27 | return sb.toString() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /formats/json/nativeMain/src/kotlinx/serialization/json/internal/createMapForCache.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.json.internal 6 | 7 | /** 8 | * Creates a ConcurrentHashMap on JVM and regular HashMap on other platforms. 9 | * To make actual use of cache in Kotlin/Native, mark a top-level object with this map 10 | * as a @[ThreadLocal]. 11 | */ 12 | internal actual fun createMapForCache(initialCapacity: Int): MutableMap = HashMap(initialCapacity) 13 | -------------------------------------------------------------------------------- /formats/properties/jvmMainModule/src/module-info.java: -------------------------------------------------------------------------------- 1 | module kotlinx.serialization.properties { 2 | requires transitive kotlin.stdlib; 3 | requires transitive kotlinx.serialization.core; 4 | 5 | exports kotlinx.serialization.properties; 6 | } 7 | -------------------------------------------------------------------------------- /formats/protobuf/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | import Java9Modularity.configureJava9ModuleInfo 5 | 6 | plugins { 7 | kotlin("multiplatform") 8 | 9 | alias(libs.plugins.serialization) 10 | 11 | id("native-targets-conventions") 12 | id("source-sets-conventions") 13 | } 14 | 15 | kotlin { 16 | sourceSets { 17 | configureEach { 18 | languageSettings.optIn("kotlinx.serialization.internal.CoreFriendModuleApi") 19 | } 20 | 21 | commonMain { 22 | dependencies { 23 | api(project(":kotlinx-serialization-core")) 24 | } 25 | } 26 | 27 | jvmTest { 28 | dependencies { 29 | implementation(project(":kotlinx-serialization-protobuf:proto-test-model")) 30 | implementation(libs.kotlintest) 31 | } 32 | } 33 | } 34 | } 35 | 36 | configureJava9ModuleInfo() 37 | -------------------------------------------------------------------------------- /formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/SuppressAnimalSniffer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.protobuf.internal 6 | 7 | /** 8 | * Suppresses Animal Sniffer plugin errors for certain methods. 9 | * Such methods include references to Java 8 methods that are not 10 | * available in Android API, but can be desugared by R8. 11 | */ 12 | @Retention(AnnotationRetention.BINARY) 13 | @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) 14 | internal annotation class SuppressAnimalSniffer -------------------------------------------------------------------------------- /formats/protobuf/commonTest/src/kotlinx/serialization/HexConverter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization 6 | 7 | object HexConverter { 8 | private const val hexCode = "0123456789ABCDEF" 9 | 10 | fun printHexBinary(data: ByteArray, lowerCase: Boolean = false): String { 11 | val r = StringBuilder(data.size * 2) 12 | for (b in data) { 13 | r.append(hexCode[b.toInt() shr 4 and 0xF]) 14 | r.append(hexCode[b.toInt() and 0xF]) 15 | } 16 | return if (lowerCase) r.toString().lowercase() else r.toString() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/MapEntryTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.protobuf 6 | 7 | import kotlinx.serialization.* 8 | import kotlin.test.* 9 | 10 | class MapEntryTest { 11 | 12 | @Serializable 13 | data class Wrapper(val e: Map.Entry) 14 | 15 | @Test 16 | fun testEntry() { 17 | val e = Wrapper(mapOf(1 to 1).entries.single()) 18 | val output = ProtoBuf.encodeToHexString(Wrapper.serializer(), e) 19 | assertEquals("0a0408011001", output) 20 | assertEquals(e.e.toPair(), ProtoBuf.decodeFromHexString(Wrapper.serializer(), output).e.toPair()) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /formats/protobuf/commonTest/src/kotlinx/serialization/test/CurrentPlatform.common.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | enum class Platform { 8 | JVM, JS, NATIVE, WASM 9 | } 10 | 11 | public expect val currentPlatform: Platform 12 | 13 | public fun isJs(): Boolean = currentPlatform == Platform.JS 14 | 15 | public fun isJvm(): Boolean = currentPlatform == Platform.JVM 16 | public fun isNative(): Boolean = currentPlatform == Platform.NATIVE 17 | public fun isWasm(): Boolean = currentPlatform == Platform.WASM -------------------------------------------------------------------------------- /formats/protobuf/jsMain/src/kotlinx/serialization/protobuf/internal/Bytes.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.protobuf.internal 6 | 7 | private fun Short.reverseBytes(): Short = (((this.toInt() and 0xff) shl 8) or ((this.toInt() and 0xffff) ushr 8)).toShort() 8 | 9 | internal actual fun Int.reverseBytes(): Int = 10 | ((this and 0xffff).toShort().reverseBytes().toInt() shl 16) or ((this ushr 16).toShort().reverseBytes().toInt() and 0xffff) 11 | 12 | internal actual fun Long.reverseBytes(): Long = 13 | ((this and 0xffffffff).toInt().reverseBytes().toLong() shl 32) or ((this ushr 32).toInt() 14 | .reverseBytes().toLong() and 0xffffffff) 15 | -------------------------------------------------------------------------------- /formats/protobuf/jsTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | public actual val currentPlatform: Platform = Platform.JS 8 | -------------------------------------------------------------------------------- /formats/protobuf/jvmMain/src/kotlinx/serialization/protobuf/internal/Bytes.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.protobuf.internal 6 | 7 | internal actual fun Int.reverseBytes(): Int = Integer.reverseBytes(this) 8 | 9 | internal actual fun Long.reverseBytes(): Long = java.lang.Long.reverseBytes(this) 10 | -------------------------------------------------------------------------------- /formats/protobuf/jvmMainModule/src/module-info.java: -------------------------------------------------------------------------------- 1 | module kotlinx.serialization.protobuf { 2 | requires transitive kotlin.stdlib; 3 | requires transitive kotlinx.serialization.core; 4 | 5 | exports kotlinx.serialization.protobuf; 6 | exports kotlinx.serialization.protobuf.schema; 7 | } 8 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/AbstractHolder.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.AbstractHolder' 6 | message AbstractHolder { 7 | required KotlinxSerializationPolymorphic abs = 1; 8 | } 9 | 10 | // This message was generated to support polymorphic types and does not present in Kotlin. 11 | message KotlinxSerializationPolymorphic { 12 | required string type = 1; 13 | required bytes value = 2; 14 | } 15 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/ContextualHolder.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.ContextualHolder' 6 | message ContextualHolder { 7 | required bytes value = 1; 8 | } 9 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/EnumWithProtoNumber.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.EnumWithProtoNumber' 6 | enum EnumWithProtoNumber { 7 | ZERO = 0; 8 | THREE = 3; 9 | TWO = 2; 10 | FIVE = 5; 11 | } 12 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/FieldNumberClass.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.FieldNumberClass' 6 | message FieldNumberClass { 7 | required int32 a = 1; 8 | required int32 b = 5; 9 | required int32 c = 3; 10 | } 11 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/ListClass.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.ListClass' 6 | message ListClass { 7 | repeated int32 intList = 1; 8 | repeated int32 intArray = 2; 9 | // WARNING: nullable elements of collections can not be represented in protobuf 10 | repeated int32 boxedIntArray = 3; 11 | repeated OptionsClass messageList = 4; 12 | repeated OverriddenEnumName enumList = 5; 13 | } 14 | 15 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.OptionsClass' 16 | message OptionsClass { 17 | required int32 i = 1; 18 | } 19 | 20 | enum OverriddenEnumName { 21 | FIRST = 0; 22 | OverriddenElementName = 1; 23 | } 24 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/MapClass.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.MapClass' 6 | message MapClass { 7 | map scalarMap = 1; 8 | map bytesMap = 2; 9 | map messageMap = 3; 10 | map enumMap = 4; 11 | } 12 | 13 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.OptionsClass' 14 | message OptionsClass { 15 | required int32 i = 1; 16 | } 17 | 18 | enum OverriddenEnumName { 19 | FIRST = 0; 20 | OverriddenElementName = 1; 21 | } 22 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/OptionalCollections.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.OptionalCollections' 6 | message OptionalCollections { 7 | repeated int32 requiredList = 1; 8 | // WARNING: a default value decoded when value is missing 9 | repeated int32 optionalList = 2; 10 | // WARNING: an empty collection decoded when a value is missing 11 | repeated int32 nullableList = 3; 12 | // WARNING: a default value decoded when value is missing 13 | repeated int32 nullableOptionalList = 4; 14 | map requiredMap = 5; 15 | // WARNING: a default value decoded when value is missing 16 | map optionalMap = 6; 17 | // WARNING: an empty collection decoded when a value is missing 18 | map nullableMap = 7; 19 | // WARNING: a default value decoded when value is missing 20 | map nullableOptionalMap = 8; 21 | } 22 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/OptionsClass.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | option java_package = "api.proto"; 5 | option java_outer_classname = "Outer"; 6 | 7 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.OptionsClass' 8 | message OptionsClass { 9 | required int32 i = 1; 10 | } 11 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/PackedListClass.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.PackedListClass' 6 | message PackedListClass { 7 | repeated int32 intList = 1 [packed=true]; 8 | repeated int32 intArray = 2 [packed=true]; 9 | // WARNING: nullable elements of collections can not be represented in protobuf 10 | repeated int32 boxedIntArray = 3 [packed=true]; 11 | repeated OptionsClass messageList = 4; 12 | repeated OverriddenEnumName enumList = 5; 13 | } 14 | 15 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.OptionsClass' 16 | message OptionsClass { 17 | required int32 i = 1; 18 | } 19 | 20 | enum OverriddenEnumName { 21 | FIRST = 0; 22 | OverriddenElementName = 1; 23 | } 24 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/ScalarHolder.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.ScalarHolder' 6 | message ScalarHolder { 7 | required int32 int = 1; 8 | required sint32 intSigned = 2; 9 | required fixed32 intFixed = 3; 10 | required int32 intDefault = 4; 11 | required int64 long = 5; 12 | required sint64 longSigned = 6; 13 | required fixed64 longFixed = 7; 14 | required int32 longDefault = 8; 15 | required bool flag = 9; 16 | required bytes byteArray = 10; 17 | required bytes boxedByteArray = 11; 18 | required string text = 12; 19 | required float float = 13; 20 | required double double = 14; 21 | } 22 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/resources/SerialNameClass.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package kotlinx.serialization.protobuf.schema.generator; 4 | 5 | message OverriddenClassName { 6 | required int32 original = 1; 7 | required OverriddenEnumName OverriddenFieldName = 2; 8 | } 9 | 10 | enum OverriddenEnumName { 11 | FIRST = 0; 12 | OverriddenElementName = 1; 13 | } 14 | -------------------------------------------------------------------------------- /formats/protobuf/jvmTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | actual val currentPlatform: Platform = Platform.JVM 8 | -------------------------------------------------------------------------------- /formats/protobuf/nativeMain/src/kotlinx/serialization/protobuf/internal/Bytes.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.protobuf.internal 6 | 7 | private fun Short.reverseBytes(): Short = (((this.toInt() and 0xff) shl 8) or ((this.toInt() and 0xffff) ushr 8)).toShort() 8 | 9 | internal actual fun Int.reverseBytes(): Int = 10 | ((this and 0xffff).toShort().reverseBytes().toInt() shl 16) or ((this ushr 16).toShort().reverseBytes().toInt() and 0xffff) 11 | 12 | internal actual fun Long.reverseBytes(): Long = 13 | ((this and 0xffffffff).toInt().reverseBytes().toLong() shl 32) or ((this ushr 32).toInt() 14 | .reverseBytes().toLong() and 0xffffffff) 15 | -------------------------------------------------------------------------------- /formats/protobuf/nativeTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | 8 | public actual val currentPlatform: Platform = Platform.NATIVE 9 | -------------------------------------------------------------------------------- /formats/protobuf/proto-test-model/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | import com.google.protobuf.gradle.* 6 | import org.gradle.kotlin.dsl.protobuf 7 | 8 | plugins { 9 | `java-library` 10 | alias(libs.plugins.protobuf) 11 | } 12 | 13 | protobuf { 14 | protobuf.protoc { 15 | // Download from repositories 16 | artifact = libs.protoc.get().toString() 17 | } 18 | } 19 | 20 | // Toolchain version should be the same as JDK release in source-sets-convention 21 | java.toolchain.languageVersion.set(JavaLanguageVersion.of(8)) 22 | 23 | tasks.clean { 24 | delete(protobuf.protobuf.generatedFilesBaseDir) 25 | } 26 | 27 | sourceSets.main { 28 | extensions.configure("proto") { 29 | srcDirs("testProto", "../jvmTest/resources/common") 30 | } 31 | } 32 | 33 | dependencies { 34 | api(libs.protobuf.java) 35 | } 36 | -------------------------------------------------------------------------------- /formats/protobuf/wasmMain/src/kotlinx/serialization/protobuf/internal/Bytes.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.protobuf.internal 6 | 7 | private fun Short.reverseBytes(): Short = (((this.toInt() and 0xff) shl 8) or ((this.toInt() and 0xffff) ushr 8)).toShort() 8 | 9 | internal actual fun Int.reverseBytes(): Int = 10 | ((this and 0xffff).toShort().reverseBytes().toInt() shl 16) or ((this ushr 16).toShort().reverseBytes().toInt() and 0xffff) 11 | 12 | internal actual fun Long.reverseBytes(): Long = 13 | ((this and 0xffffffff).toInt().reverseBytes().toLong() shl 32) or ((this ushr 32).toInt() 14 | .reverseBytes().toLong() and 0xffffffff) 15 | -------------------------------------------------------------------------------- /formats/protobuf/wasmTest/src/kotlinx/serialization/test/CurrentPlatform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package kotlinx.serialization.test 6 | 7 | public actual val currentPlatform: Platform = Platform.WASM -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | # 4 | 5 | group=org.jetbrains.kotlinx 6 | version=1.8.2-SNAPSHOT 7 | jdk_toolchain_version=11 8 | 9 | # This version takes precedence if 'bootstrap' property passed to project 10 | kotlin.version.snapshot=2.1.255-SNAPSHOT 11 | # Also set kotlin.native.home to your $kotlin_project$/kotlin-native/dist if you want to use snapshot Native 12 | #kotlin.native.home= 13 | 14 | kover.enabled=true 15 | 16 | org.gradle.parallel=true 17 | org.gradle.caching=true 18 | org.gradle.kotlin.dsl.allWarningsAsErrors=true 19 | 20 | #kotlin.native.jvmArgs=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5007 21 | #kotlin.native.disableCompilerDaemon=true 22 | 23 | kotlin.native.distribution.type=prebuilt 24 | 25 | org.gradle.jvmargs="-XX:+HeapDumpOnOutOfMemoryError" 26 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionSha256Sum=544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /guide/README.md: -------------------------------------------------------------------------------- 1 | Example files for the [Kotlin Serialization Guide](../docs/serialization-guide.md). -------------------------------------------------------------------------------- /guide/example/example-basic-01.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleBasic01 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | class Project(val name: String, val language: String) 8 | 9 | fun main() { 10 | val data = Project("kotlinx.serialization", "Kotlin") 11 | println(Json.encodeToString(data)) 12 | } 13 | -------------------------------------------------------------------------------- /guide/example/example-basic-02.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleBasic02 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String, val language: String) 9 | 10 | fun main() { 11 | val data = Project("kotlinx.serialization", "Kotlin") 12 | println(Json.encodeToString(data)) 13 | } 14 | -------------------------------------------------------------------------------- /guide/example/example-basic-03.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleBasic03 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val name: String, val language: String) 9 | 10 | fun main() { 11 | val data = Json.decodeFromString(""" 12 | {"name":"kotlinx.serialization","language":"Kotlin"} 13 | """) 14 | println(data) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-builtin-01.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin01 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlin.math.* 8 | 9 | @Serializable 10 | class Data( 11 | val answer: Int, 12 | val pi: Double 13 | ) 14 | 15 | fun main() { 16 | val data = Data(42, PI) 17 | println(Json.encodeToString(data)) 18 | } 19 | -------------------------------------------------------------------------------- /guide/example/example-builtin-02.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin02 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Data(val signature: Long) 9 | 10 | fun main() { 11 | val data = Data(0x1CAFE2FEED0BABE0) 12 | println(Json.encodeToString(data)) 13 | } 14 | -------------------------------------------------------------------------------- /guide/example/example-builtin-03.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin03 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.builtins.* 8 | 9 | @Serializable 10 | class Data( 11 | @Serializable(with=LongAsStringSerializer::class) 12 | val signature: Long 13 | ) 14 | 15 | fun main() { 16 | val data = Data(0x1CAFE2FEED0BABE0) 17 | println(Json.encodeToString(data)) 18 | } 19 | -------------------------------------------------------------------------------- /guide/example/example-builtin-04.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin04 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | // The @Serializable annotation is not needed for enum classes 8 | enum class Status { SUPPORTED } 9 | 10 | @Serializable 11 | class Project(val name: String, val status: Status) 12 | 13 | fun main() { 14 | val data = Project("kotlinx.serialization", Status.SUPPORTED) 15 | println(Json.encodeToString(data)) 16 | } 17 | -------------------------------------------------------------------------------- /guide/example/example-builtin-05.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin05 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable // required because of @SerialName 8 | enum class Status { @SerialName("maintained") SUPPORTED } 9 | 10 | @Serializable 11 | class Project(val name: String, val status: Status) 12 | 13 | fun main() { 14 | val data = Project("kotlinx.serialization", Status.SUPPORTED) 15 | println(Json.encodeToString(data)) 16 | } 17 | -------------------------------------------------------------------------------- /guide/example/example-builtin-06.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin06 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String) 9 | 10 | fun main() { 11 | val pair = 1 to Project("kotlinx.serialization") 12 | println(Json.encodeToString(pair)) 13 | } 14 | -------------------------------------------------------------------------------- /guide/example/example-builtin-07.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin07 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String) 9 | 10 | fun main() { 11 | val list = listOf( 12 | Project("kotlinx.serialization"), 13 | Project("kotlinx.coroutines") 14 | ) 15 | println(Json.encodeToString(list)) 16 | } 17 | -------------------------------------------------------------------------------- /guide/example/example-builtin-08.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin08 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String) 9 | 10 | fun main() { 11 | val set = setOf( 12 | Project("kotlinx.serialization"), 13 | Project("kotlinx.coroutines") 14 | ) 15 | println(Json.encodeToString(set)) 16 | } 17 | -------------------------------------------------------------------------------- /guide/example/example-builtin-09.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin09 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Data( 9 | val a: List, 10 | val b: Set 11 | ) 12 | 13 | fun main() { 14 | val data = Json.decodeFromString(""" 15 | { 16 | "a": [42, 42], 17 | "b": [42, 42] 18 | } 19 | """) 20 | println(data) 21 | } 22 | -------------------------------------------------------------------------------- /guide/example/example-builtin-10.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin10 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String) 9 | 10 | fun main() { 11 | val map = mapOf( 12 | 1 to Project("kotlinx.serialization"), 13 | 2 to Project("kotlinx.coroutines") 14 | ) 15 | println(Json.encodeToString(map)) 16 | } 17 | -------------------------------------------------------------------------------- /guide/example/example-builtin-11.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin11 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | object SerializationVersion { 9 | val libraryVersion: String = "1.0.0" 10 | } 11 | 12 | fun main() { 13 | println(Json.encodeToString(SerializationVersion)) 14 | println(Json.encodeToString(Unit)) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-builtin-12.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin12 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlin.time.* 8 | 9 | fun main() { 10 | val duration = 1000.toDuration(DurationUnit.SECONDS) 11 | println(Json.encodeToString(duration)) 12 | } 13 | -------------------------------------------------------------------------------- /guide/example/example-builtin-13.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from builtin-classes.md by Knit tool. Do not edit. 2 | package example.exampleBuiltin13 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | sealed class ParametrizedParent { 9 | @Serializable 10 | data class ChildWithoutParameter(val value: Int) : ParametrizedParent() 11 | } 12 | 13 | fun main() { 14 | println(Json.encodeToString(ParametrizedParent.ChildWithoutParameter(42))) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-classes-01.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses01 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project( 9 | // name is a property with backing field -- serialized 10 | var name: String 11 | ) { 12 | var stars: Int = 0 // property with a backing field -- serialized 13 | 14 | val path: String // getter only, no backing field -- not serialized 15 | get() = "kotlin/$name" 16 | 17 | var id by ::name // delegated property -- not serialized 18 | } 19 | 20 | fun main() { 21 | val data = Project("kotlinx.serialization").apply { stars = 9000 } 22 | println(Json.encodeToString(data)) 23 | } 24 | -------------------------------------------------------------------------------- /guide/example/example-classes-02.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses02 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project private constructor(val owner: String, val name: String) { 9 | constructor(path: String) : this( 10 | owner = path.substringBefore('/'), 11 | name = path.substringAfter('/') 12 | ) 13 | 14 | val path: String 15 | get() = "$owner/$name" 16 | } 17 | 18 | fun main() { 19 | println(Json.encodeToString(Project("kotlin/kotlinx.serialization"))) 20 | } 21 | -------------------------------------------------------------------------------- /guide/example/example-classes-03.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses03 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String) { 9 | init { 10 | require(name.isNotEmpty()) { "name cannot be empty" } 11 | } 12 | } 13 | 14 | fun main() { 15 | val data = Json.decodeFromString(""" 16 | {"name":""} 17 | """) 18 | println(data) 19 | } 20 | -------------------------------------------------------------------------------- /guide/example/example-classes-04.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses04 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val name: String, val language: String) 9 | 10 | fun main() { 11 | val data = Json.decodeFromString(""" 12 | {"name":"kotlinx.serialization"} 13 | """) 14 | println(data) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-classes-05.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses05 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val name: String, val language: String = "Kotlin") 9 | 10 | fun main() { 11 | val data = Json.decodeFromString(""" 12 | {"name":"kotlinx.serialization"} 13 | """) 14 | println(data) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-classes-06.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses06 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | fun computeLanguage(): String { 8 | println("Computing") 9 | return "Kotlin" 10 | } 11 | 12 | @Serializable 13 | data class Project(val name: String, val language: String = computeLanguage()) 14 | 15 | fun main() { 16 | val data = Json.decodeFromString(""" 17 | {"name":"kotlinx.serialization","language":"Kotlin"} 18 | """) 19 | println(data) 20 | } 21 | -------------------------------------------------------------------------------- /guide/example/example-classes-07.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses07 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val name: String, @Required val language: String = "Kotlin") 9 | 10 | fun main() { 11 | val data = Json.decodeFromString(""" 12 | {"name":"kotlinx.serialization"} 13 | """) 14 | println(data) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-classes-08.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses08 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val name: String, @Transient val language: String = "Kotlin") 9 | 10 | fun main() { 11 | val data = Json.decodeFromString(""" 12 | {"name":"kotlinx.serialization","language":"Kotlin"} 13 | """) 14 | println(data) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-classes-09.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses09 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val name: String, val language: String = "Kotlin") 9 | 10 | fun main() { 11 | val data = Project("kotlinx.serialization") 12 | println(Json.encodeToString(data)) 13 | } 14 | -------------------------------------------------------------------------------- /guide/example/example-classes-10.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses10 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | @OptIn(ExperimentalSerializationApi::class) // EncodeDefault is an experimental annotation for now 9 | data class Project( 10 | val name: String, 11 | @EncodeDefault val language: String = "Kotlin" 12 | ) 13 | 14 | 15 | @Serializable 16 | @OptIn(ExperimentalSerializationApi::class) // EncodeDefault is an experimental annotation for now 17 | data class User( 18 | val name: String, 19 | @EncodeDefault(EncodeDefault.Mode.NEVER) val projects: List = emptyList() 20 | ) 21 | 22 | fun main() { 23 | val userA = User("Alice", listOf(Project("kotlinx.serialization"))) 24 | val userB = User("Bob") 25 | println(Json.encodeToString(userA)) 26 | println(Json.encodeToString(userB)) 27 | } 28 | -------------------------------------------------------------------------------- /guide/example/example-classes-11.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses11 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String, val renamedTo: String? = null) 9 | 10 | fun main() { 11 | val data = Project("kotlinx.serialization") 12 | println(Json.encodeToString(data)) 13 | } 14 | -------------------------------------------------------------------------------- /guide/example/example-classes-12.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses12 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val name: String, val language: String = "Kotlin") 9 | 10 | fun main() { 11 | val data = Json.decodeFromString(""" 12 | {"name":"kotlinx.serialization","language":null} 13 | """) 14 | println(data) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-classes-13.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses13 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String, val owner: User) 9 | 10 | @Serializable 11 | class User(val name: String) 12 | 13 | fun main() { 14 | val owner = User("kotlin") 15 | val data = Project("kotlinx.serialization", owner) 16 | println(Json.encodeToString(data)) 17 | } 18 | -------------------------------------------------------------------------------- /guide/example/example-classes-14.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses14 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String, val owner: User, val maintainer: User) 9 | 10 | @Serializable 11 | class User(val name: String) 12 | 13 | fun main() { 14 | val owner = User("kotlin") 15 | val data = Project("kotlinx.serialization", owner, owner) 16 | println(Json.encodeToString(data)) 17 | } 18 | -------------------------------------------------------------------------------- /guide/example/example-classes-15.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses15 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Box(val contents: T) 9 | 10 | @Serializable 11 | data class Project(val name: String, val language: String) 12 | 13 | @Serializable 14 | class Data( 15 | val a: Box, 16 | val b: Box 17 | ) 18 | 19 | fun main() { 20 | val data = Data(Box(42), Box(Project("kotlinx.serialization", "Kotlin"))) 21 | println(Json.encodeToString(data)) 22 | } 23 | -------------------------------------------------------------------------------- /guide/example/example-classes-16.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from basic-serialization.md by Knit tool. Do not edit. 2 | package example.exampleClasses16 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String, @SerialName("lang") val language: String) 9 | 10 | fun main() { 11 | val data = Project("kotlinx.serialization", "Kotlin") 12 | println(Json.encodeToString(data)) 13 | } 14 | -------------------------------------------------------------------------------- /guide/example/example-formats-01.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 | package example.exampleFormats01 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.cbor.* 6 | 7 | fun ByteArray.toAsciiHexString() = joinToString("") { 8 | if (it in 32..127) it.toInt().toChar().toString() else 9 | "{${it.toUByte().toString(16).padStart(2, '0').uppercase()}}" 10 | } 11 | 12 | @Serializable 13 | data class Project(val name: String, val language: String) 14 | 15 | @OptIn(ExperimentalSerializationApi::class) 16 | fun main() { 17 | val data = Project("kotlinx.serialization", "Kotlin") 18 | val bytes = Cbor.encodeToByteArray(data) 19 | println(bytes.toAsciiHexString()) 20 | val obj = Cbor.decodeFromByteArray(bytes) 21 | println(obj) 22 | } 23 | -------------------------------------------------------------------------------- /guide/example/example-formats-02.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 | package example.exampleFormats02 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.cbor.* 6 | 7 | @Serializable 8 | data class Project(val name: String) 9 | 10 | @OptIn(ExperimentalSerializationApi::class) 11 | fun main() { 12 | val format = Cbor { ignoreUnknownKeys = true } 13 | 14 | val data = format.decodeFromHexString( 15 | "bf646e616d65756b6f746c696e782e73657269616c697a6174696f6e686c616e6775616765664b6f746c696eff" 16 | ) 17 | println(data) 18 | } 19 | -------------------------------------------------------------------------------- /guide/example/example-formats-03.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 | package example.exampleFormats03 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.cbor.* 6 | 7 | fun ByteArray.toAsciiHexString() = joinToString("") { 8 | if (it in 32..127) it.toInt().toChar().toString() else 9 | "{${it.toUByte().toString(16).padStart(2, '0').uppercase()}}" 10 | } 11 | 12 | @Serializable 13 | @OptIn(ExperimentalSerializationApi::class) 14 | data class Data( 15 | @ByteString 16 | val type2: ByteArray, // CBOR Major type 2 17 | val type4: ByteArray // CBOR Major type 4 18 | ) 19 | 20 | @OptIn(ExperimentalSerializationApi::class) 21 | fun main() { 22 | val data = Data(byteArrayOf(1, 2, 3, 4), byteArrayOf(5, 6, 7, 8)) 23 | val bytes = Cbor.encodeToByteArray(data) 24 | println(bytes.toAsciiHexString()) 25 | val obj = Cbor.decodeFromByteArray(bytes) 26 | println(obj) 27 | } 28 | -------------------------------------------------------------------------------- /guide/example/example-formats-04.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 | package example.exampleFormats04 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.protobuf.* 6 | 7 | fun ByteArray.toAsciiHexString() = joinToString("") { 8 | if (it in 32..127) it.toInt().toChar().toString() else 9 | "{${it.toUByte().toString(16).padStart(2, '0').uppercase()}}" 10 | } 11 | 12 | @Serializable 13 | data class Project(val name: String, val language: String) 14 | 15 | @OptIn(ExperimentalSerializationApi::class) 16 | fun main() { 17 | val data = Project("kotlinx.serialization", "Kotlin") 18 | val bytes = ProtoBuf.encodeToByteArray(data) 19 | println(bytes.toAsciiHexString()) 20 | val obj = ProtoBuf.decodeFromByteArray(bytes) 21 | println(obj) 22 | } 23 | -------------------------------------------------------------------------------- /guide/example/example-formats-05.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 | package example.exampleFormats05 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.protobuf.* 6 | 7 | fun ByteArray.toAsciiHexString() = joinToString("") { 8 | if (it in 32..127) it.toInt().toChar().toString() else 9 | "{${it.toUByte().toString(16).padStart(2, '0').uppercase()}}" 10 | } 11 | 12 | @OptIn(ExperimentalSerializationApi::class) 13 | @Serializable 14 | data class Project( 15 | @ProtoNumber(1) 16 | val name: String, 17 | @ProtoNumber(3) 18 | val language: String 19 | ) 20 | 21 | @OptIn(ExperimentalSerializationApi::class) 22 | fun main() { 23 | val data = Project("kotlinx.serialization", "Kotlin") 24 | val bytes = ProtoBuf.encodeToByteArray(data) 25 | println(bytes.toAsciiHexString()) 26 | val obj = ProtoBuf.decodeFromByteArray(bytes) 27 | println(obj) 28 | } 29 | -------------------------------------------------------------------------------- /guide/example/example-formats-06.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 | package example.exampleFormats06 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.protobuf.* 6 | 7 | fun ByteArray.toAsciiHexString() = joinToString("") { 8 | if (it in 32..127) it.toInt().toChar().toString() else 9 | "{${it.toUByte().toString(16).padStart(2, '0').uppercase()}}" 10 | } 11 | 12 | @OptIn(ExperimentalSerializationApi::class) 13 | @Serializable 14 | class Data( 15 | @ProtoType(ProtoIntegerType.DEFAULT) 16 | val a: Int, 17 | @ProtoType(ProtoIntegerType.SIGNED) 18 | val b: Int, 19 | @ProtoType(ProtoIntegerType.FIXED) 20 | val c: Int 21 | ) 22 | 23 | @OptIn(ExperimentalSerializationApi::class) 24 | fun main() { 25 | val data = Data(1, -2, 3) 26 | println(ProtoBuf.encodeToByteArray(data).toAsciiHexString()) 27 | } 28 | -------------------------------------------------------------------------------- /guide/example/example-formats-07.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 | package example.exampleFormats07 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.protobuf.* 6 | 7 | fun ByteArray.toAsciiHexString() = joinToString("") { 8 | if (it in 32..127) it.toInt().toChar().toString() else 9 | "{${it.toUByte().toString(16).padStart(2, '0').uppercase()}}" 10 | } 11 | 12 | @Serializable 13 | data class Data( 14 | val a: List = emptyList(), 15 | val b: List = emptyList() 16 | ) 17 | 18 | @OptIn(ExperimentalSerializationApi::class) 19 | fun main() { 20 | val data = Data(listOf(1, 2, 3), listOf()) 21 | val bytes = ProtoBuf.encodeToByteArray(data) 22 | println(bytes.toAsciiHexString()) 23 | println(ProtoBuf.decodeFromByteArray(bytes)) 24 | } 25 | -------------------------------------------------------------------------------- /guide/example/example-formats-09.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 | package example.exampleFormats09 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.protobuf.* 6 | import kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator 7 | 8 | @Serializable 9 | data class SampleData( 10 | val amount: Long, 11 | val description: String?, 12 | val department: String = "QA" 13 | ) 14 | 15 | @OptIn(ExperimentalSerializationApi::class) 16 | fun main() { 17 | val descriptors = listOf(SampleData.serializer().descriptor) 18 | val schemas = ProtoBufSchemaGenerator.generateSchemaText(descriptors) 19 | println(schemas) 20 | } 21 | -------------------------------------------------------------------------------- /guide/example/example-formats-10.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 | package example.exampleFormats10 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.properties.Properties // todo: remove when no longer needed 6 | import kotlinx.serialization.properties.* 7 | 8 | @Serializable 9 | class Project(val name: String, val owner: User) 10 | 11 | @Serializable 12 | class User(val name: String) 13 | 14 | @OptIn(ExperimentalSerializationApi::class) 15 | fun main() { 16 | val data = Project("kotlinx.serialization", User("kotlin")) 17 | val map = Properties.encodeToMap(data) 18 | map.forEach { (k, v) -> println("$k = $v") } 19 | } 20 | -------------------------------------------------------------------------------- /guide/example/example-json-01.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson01 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | val format = Json { prettyPrint = true } 8 | 9 | @Serializable 10 | data class Project(val name: String, val language: String) 11 | 12 | fun main() { 13 | val data = Project("kotlinx.serialization", "Kotlin") 14 | println(format.encodeToString(data)) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-json-02.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson02 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | val format = Json { isLenient = true } 8 | 9 | enum class Status { SUPPORTED } 10 | 11 | @Serializable 12 | data class Project(val name: String, val status: Status, val votes: Int) 13 | 14 | fun main() { 15 | val data = format.decodeFromString(""" 16 | { 17 | name : kotlinx.serialization, 18 | status : SUPPORTED, 19 | votes : "9000" 20 | } 21 | """) 22 | println(data) 23 | } 24 | -------------------------------------------------------------------------------- /guide/example/example-json-03.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson03 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | val format = Json { ignoreUnknownKeys = true } 8 | 9 | @Serializable 10 | data class Project(val name: String) 11 | 12 | fun main() { 13 | val data = format.decodeFromString(""" 14 | {"name":"kotlinx.serialization","language":"Kotlin"} 15 | """) 16 | println(data) 17 | } 18 | -------------------------------------------------------------------------------- /guide/example/example-json-04.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson04 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @OptIn(ExperimentalSerializationApi::class) // JsonIgnoreUnknownKeys is an experimental annotation for now 8 | @Serializable 9 | @JsonIgnoreUnknownKeys 10 | data class Outer(val a: Int, val inner: Inner) 11 | 12 | @Serializable 13 | data class Inner(val x: String) 14 | 15 | fun main() { 16 | // 1 17 | println(Json.decodeFromString("""{"a":1,"inner":{"x":"value"},"unknownKey":42}""")) 18 | println() 19 | // 2 20 | println(Json.decodeFromString("""{"a":1,"inner":{"x":"value","unknownKey":"unknownValue"}}""")) 21 | } 22 | -------------------------------------------------------------------------------- /guide/example/example-json-05.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson05 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @OptIn(ExperimentalSerializationApi::class) // JsonNames is an experimental annotation for now 8 | @Serializable 9 | data class Project(@JsonNames("title") val name: String) 10 | 11 | fun main() { 12 | val project = Json.decodeFromString("""{"name":"kotlinx.serialization"}""") 13 | println(project) 14 | val oldProject = Json.decodeFromString("""{"title":"kotlinx.coroutines"}""") 15 | println(oldProject) 16 | } 17 | -------------------------------------------------------------------------------- /guide/example/example-json-06.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson06 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | val format = Json { encodeDefaults = true } 8 | 9 | @Serializable 10 | class Project( 11 | val name: String, 12 | val language: String = "Kotlin", 13 | val website: String? = null 14 | ) 15 | 16 | fun main() { 17 | val data = Project("kotlinx.serialization") 18 | println(format.encodeToString(data)) 19 | } 20 | -------------------------------------------------------------------------------- /guide/example/example-json-07.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson07 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | val format = Json { explicitNulls = false } 8 | 9 | @Serializable 10 | data class Project( 11 | val name: String, 12 | val language: String, 13 | val version: String? = "1.2.2", 14 | val website: String?, 15 | val description: String? = null 16 | ) 17 | 18 | fun main() { 19 | val data = Project("kotlinx.serialization", "Kotlin", null, null, null) 20 | val json = format.encodeToString(data) 21 | println(json) 22 | println(format.decodeFromString(json)) 23 | } 24 | -------------------------------------------------------------------------------- /guide/example/example-json-08.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson08 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | val format = Json { coerceInputValues = true } 8 | 9 | @Serializable 10 | data class Project(val name: String, val language: String = "Kotlin") 11 | 12 | fun main() { 13 | val data = format.decodeFromString(""" 14 | {"name":"kotlinx.serialization","language":null} 15 | """) 16 | println(data) 17 | } 18 | -------------------------------------------------------------------------------- /guide/example/example-json-09.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson09 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | enum class Color { BLACK, WHITE } 8 | 9 | @Serializable 10 | data class Brush(val foreground: Color = Color.BLACK, val background: Color?) 11 | 12 | val json = Json { 13 | coerceInputValues = true 14 | explicitNulls = false 15 | } 16 | 17 | fun main() { 18 | val brush = json.decodeFromString("""{"foreground":"pink", "background":"purple"}""") 19 | println(brush) 20 | } 21 | -------------------------------------------------------------------------------- /guide/example/example-json-10.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson10 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | val format = Json { allowStructuredMapKeys = true } 8 | 9 | @Serializable 10 | data class Project(val name: String) 11 | 12 | fun main() { 13 | val map = mapOf( 14 | Project("kotlinx.serialization") to "Serialization", 15 | Project("kotlinx.coroutines") to "Coroutines" 16 | ) 17 | println(format.encodeToString(map)) 18 | } 19 | -------------------------------------------------------------------------------- /guide/example/example-json-11.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson11 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | val format = Json { allowSpecialFloatingPointValues = true } 8 | 9 | @Serializable 10 | class Data( 11 | val value: Double 12 | ) 13 | 14 | fun main() { 15 | val data = Data(Double.NaN) 16 | println(format.encodeToString(data)) 17 | } 18 | -------------------------------------------------------------------------------- /guide/example/example-json-12.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson12 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | val format = Json { classDiscriminator = "#class" } 8 | 9 | @Serializable 10 | sealed class Project { 11 | abstract val name: String 12 | } 13 | 14 | @Serializable 15 | @SerialName("owned") 16 | class OwnedProject(override val name: String, val owner: String) : Project() 17 | 18 | fun main() { 19 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") 20 | println(format.encodeToString(data)) 21 | } 22 | -------------------------------------------------------------------------------- /guide/example/example-json-14.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson14 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @OptIn(ExperimentalSerializationApi::class) // classDiscriminatorMode is an experimental setting for now 8 | val format = Json { classDiscriminatorMode = ClassDiscriminatorMode.NONE } 9 | 10 | @Serializable 11 | sealed class Project { 12 | abstract val name: String 13 | } 14 | 15 | @Serializable 16 | class OwnedProject(override val name: String, val owner: String) : Project() 17 | 18 | fun main() { 19 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") 20 | println(format.encodeToString(data)) 21 | } 22 | -------------------------------------------------------------------------------- /guide/example/example-json-15.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson15 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @OptIn(ExperimentalSerializationApi::class) // decodeEnumsCaseInsensitive is an experimental setting for now 8 | val format = Json { decodeEnumsCaseInsensitive = true } 9 | 10 | @OptIn(ExperimentalSerializationApi::class) // JsonNames is an experimental annotation for now 11 | enum class Cases { VALUE_A, @JsonNames("Alternative") VALUE_B } 12 | 13 | @Serializable 14 | data class CasesList(val cases: List) 15 | 16 | fun main() { 17 | println(format.decodeFromString("""{"cases":["value_A", "alternative"]}""")) 18 | } 19 | -------------------------------------------------------------------------------- /guide/example/example-json-16.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson16 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val projectName: String, val projectOwner: String) 9 | 10 | @OptIn(ExperimentalSerializationApi::class) // namingStrategy is an experimental setting for now 11 | val format = Json { namingStrategy = JsonNamingStrategy.SnakeCase } 12 | 13 | fun main() { 14 | val project = format.decodeFromString("""{"project_name":"kotlinx.coroutines", "project_owner":"Kotlin"}""") 15 | println(format.encodeToString(project.copy(projectName = "kotlinx.serialization"))) 16 | } 17 | -------------------------------------------------------------------------------- /guide/example/example-json-18.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson18 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | fun main() { 8 | val element = Json.parseToJsonElement(""" 9 | {"name":"kotlinx.serialization","language":"Kotlin"} 10 | """) 11 | println(element) 12 | } 13 | -------------------------------------------------------------------------------- /guide/example/example-json-19.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson19 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | fun main() { 8 | val element = Json.parseToJsonElement(""" 9 | { 10 | "name": "kotlinx.serialization", 11 | "forks": [{"votes": 42}, {"votes": 9000}, {}] 12 | } 13 | """) 14 | val sum = element 15 | .jsonObject["forks"]!! 16 | .jsonArray.sumOf { it.jsonObject["votes"]?.jsonPrimitive?.int ?: 0 } 17 | println(sum) 18 | } 19 | -------------------------------------------------------------------------------- /guide/example/example-json-20.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson20 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | fun main() { 8 | val element = buildJsonObject { 9 | put("name", "kotlinx.serialization") 10 | putJsonObject("owner") { 11 | put("name", "kotlin") 12 | } 13 | putJsonArray("forks") { 14 | addJsonObject { 15 | put("votes", 42) 16 | } 17 | addJsonObject { 18 | put("votes", 9000) 19 | } 20 | } 21 | } 22 | println(element) 23 | } 24 | -------------------------------------------------------------------------------- /guide/example/example-json-21.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson21 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val name: String, val language: String) 9 | 10 | fun main() { 11 | val element = buildJsonObject { 12 | put("name", "kotlinx.serialization") 13 | put("language", "Kotlin") 14 | } 15 | val data = Json.decodeFromJsonElement(element) 16 | println(data) 17 | } 18 | -------------------------------------------------------------------------------- /guide/example/example-json-22.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson22 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import java.math.BigDecimal 8 | 9 | val format = Json { prettyPrint = true } 10 | 11 | fun main() { 12 | val pi = BigDecimal("3.141592653589793238462643383279") 13 | 14 | val piJsonDouble = JsonPrimitive(pi.toDouble()) 15 | val piJsonString = JsonPrimitive(pi.toString()) 16 | 17 | val piObject = buildJsonObject { 18 | put("pi_double", piJsonDouble) 19 | put("pi_string", piJsonString) 20 | } 21 | 22 | println(format.encodeToString(piObject)) 23 | } 24 | -------------------------------------------------------------------------------- /guide/example/example-json-23.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson23 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import java.math.BigDecimal 8 | 9 | val format = Json { prettyPrint = true } 10 | 11 | fun main() { 12 | val pi = BigDecimal("3.141592653589793238462643383279") 13 | 14 | // use JsonUnquotedLiteral to encode raw JSON content 15 | @OptIn(ExperimentalSerializationApi::class) 16 | val piJsonLiteral = JsonUnquotedLiteral(pi.toString()) 17 | 18 | val piJsonDouble = JsonPrimitive(pi.toDouble()) 19 | val piJsonString = JsonPrimitive(pi.toString()) 20 | 21 | val piObject = buildJsonObject { 22 | put("pi_literal", piJsonLiteral) 23 | put("pi_double", piJsonDouble) 24 | put("pi_string", piJsonString) 25 | } 26 | 27 | println(format.encodeToString(piObject)) 28 | } 29 | -------------------------------------------------------------------------------- /guide/example/example-json-24.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson24 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import java.math.BigDecimal 8 | 9 | fun main() { 10 | val piObjectJson = """ 11 | { 12 | "pi_literal": 3.141592653589793238462643383279 13 | } 14 | """.trimIndent() 15 | 16 | val piObject: JsonObject = Json.decodeFromString(piObjectJson) 17 | 18 | val piJsonLiteral = piObject["pi_literal"]!!.jsonPrimitive.content 19 | 20 | val pi = BigDecimal(piJsonLiteral) 21 | 22 | println(pi) 23 | } 24 | -------------------------------------------------------------------------------- /guide/example/example-json-25.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson25 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @OptIn(ExperimentalSerializationApi::class) 8 | fun main() { 9 | // caution: creating null with JsonUnquotedLiteral will cause an exception! 10 | JsonUnquotedLiteral("null") 11 | } 12 | -------------------------------------------------------------------------------- /guide/example/example-json-27.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson27 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.builtins.* 8 | 9 | @Serializable 10 | data class Project( 11 | val name: String, 12 | @Serializable(with = UserListSerializer::class) 13 | val users: List 14 | ) 15 | 16 | @Serializable 17 | data class User(val name: String) 18 | 19 | object UserListSerializer : JsonTransformingSerializer>(ListSerializer(User.serializer())) { 20 | 21 | override fun transformSerialize(element: JsonElement): JsonElement { 22 | require(element is JsonArray) // this serializer is used only with lists 23 | return element.singleOrNull() ?: element 24 | } 25 | } 26 | 27 | fun main() { 28 | val data = Project("kotlinx.serialization", listOf(User("kotlin"))) 29 | println(Json.encodeToString(data)) 30 | } 31 | -------------------------------------------------------------------------------- /guide/example/example-json-28.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from json.md by Knit tool. Do not edit. 2 | package example.exampleJson28 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Project(val name: String, val language: String) 9 | 10 | object ProjectSerializer : JsonTransformingSerializer(Project.serializer()) { 11 | override fun transformSerialize(element: JsonElement): JsonElement = 12 | // Filter out top-level key value pair with the key "language" and the value "Kotlin" 13 | JsonObject(element.jsonObject.filterNot { 14 | (k, v) -> k == "language" && v.jsonPrimitive.content == "Kotlin" 15 | }) 16 | } 17 | 18 | fun main() { 19 | val data = Project("kotlinx.serialization", "Kotlin") 20 | println(Json.encodeToString(data)) // using plugin-generated serializer 21 | println(Json.encodeToString(ProjectSerializer, data)) // using custom serializer 22 | } 23 | -------------------------------------------------------------------------------- /guide/example/example-poly-01.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly01 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | open class Project(val name: String) 9 | 10 | class OwnedProject(name: String, val owner: String) : Project(name) 11 | 12 | fun main() { 13 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") 14 | println(Json.encodeToString(data)) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-poly-02.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly02 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | open class Project(val name: String) 9 | 10 | class OwnedProject(name: String, val owner: String) : Project(name) 11 | 12 | fun main() { 13 | val data = OwnedProject("kotlinx.coroutines", "kotlin") 14 | println(Json.encodeToString(data)) 15 | } 16 | -------------------------------------------------------------------------------- /guide/example/example-poly-03.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly03 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | abstract class Project { 9 | abstract val name: String 10 | } 11 | 12 | class OwnedProject(override val name: String, val owner: String) : Project() 13 | 14 | fun main() { 15 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") 16 | println(Json.encodeToString(data)) 17 | } 18 | -------------------------------------------------------------------------------- /guide/example/example-poly-04.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly04 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | sealed class Project { 9 | abstract val name: String 10 | } 11 | 12 | @Serializable 13 | class OwnedProject(override val name: String, val owner: String) : Project() 14 | 15 | fun main() { 16 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") 17 | println(Json.encodeToString(data)) // Serializing data of compile-time type Project 18 | } 19 | -------------------------------------------------------------------------------- /guide/example/example-poly-05.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly05 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | sealed class Project { 9 | abstract val name: String 10 | } 11 | 12 | @Serializable 13 | class OwnedProject(override val name: String, val owner: String) : Project() 14 | 15 | fun main() { 16 | val data = OwnedProject("kotlinx.coroutines", "kotlin") // data: OwnedProject here 17 | println(Json.encodeToString(data)) // Serializing data of compile-time type OwnedProject 18 | } 19 | -------------------------------------------------------------------------------- /guide/example/example-poly-06.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly06 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | sealed class Project { 9 | abstract val name: String 10 | } 11 | 12 | @Serializable 13 | @SerialName("owned") 14 | class OwnedProject(override val name: String, val owner: String) : Project() 15 | 16 | fun main() { 17 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") 18 | println(Json.encodeToString(data)) 19 | } 20 | -------------------------------------------------------------------------------- /guide/example/example-poly-07.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly07 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | sealed class Project { 9 | abstract val name: String 10 | var status = "open" 11 | } 12 | 13 | @Serializable 14 | @SerialName("owned") 15 | class OwnedProject(override val name: String, val owner: String) : Project() 16 | 17 | fun main() { 18 | val json = Json { encodeDefaults = true } // "status" will be skipped otherwise 19 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") 20 | println(json.encodeToString(data)) 21 | } 22 | -------------------------------------------------------------------------------- /guide/example/example-poly-08.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly08 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | sealed class Response 9 | 10 | @Serializable 11 | object EmptyResponse : Response() 12 | 13 | @Serializable 14 | class TextResponse(val text: String) : Response() 15 | 16 | fun main() { 17 | val list = listOf(EmptyResponse, TextResponse("OK")) 18 | println(Json.encodeToString(list)) 19 | } 20 | -------------------------------------------------------------------------------- /guide/example/example-poly-09.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly09 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.modules.* 8 | 9 | val module = SerializersModule { 10 | polymorphic(Project::class) { 11 | subclass(OwnedProject::class) 12 | } 13 | } 14 | 15 | val format = Json { serializersModule = module } 16 | 17 | @Serializable 18 | abstract class Project { 19 | abstract val name: String 20 | } 21 | 22 | @Serializable 23 | @SerialName("owned") 24 | class OwnedProject(override val name: String, val owner: String) : Project() 25 | 26 | fun main() { 27 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") 28 | println(format.encodeToString(data)) 29 | } 30 | -------------------------------------------------------------------------------- /guide/example/example-poly-10.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly10 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.modules.* 8 | 9 | val module = SerializersModule { 10 | polymorphic(Project::class) { 11 | subclass(OwnedProject::class) 12 | } 13 | } 14 | 15 | val format = Json { serializersModule = module } 16 | 17 | interface Project { 18 | val name: String 19 | } 20 | 21 | @Serializable 22 | @SerialName("owned") 23 | class OwnedProject(override val name: String, val owner: String) : Project 24 | 25 | fun main() { 26 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") 27 | println(format.encodeToString(data)) 28 | } 29 | -------------------------------------------------------------------------------- /guide/example/example-poly-11.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly11 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.modules.* 8 | 9 | val module = SerializersModule { 10 | polymorphic(Project::class) { 11 | subclass(OwnedProject::class) 12 | } 13 | } 14 | 15 | val format = Json { serializersModule = module } 16 | 17 | interface Project { 18 | val name: String 19 | } 20 | 21 | @Serializable 22 | @SerialName("owned") 23 | class OwnedProject(override val name: String, val owner: String) : Project 24 | 25 | @Serializable 26 | class Data(val project: Project) // Project is an interface 27 | 28 | fun main() { 29 | val data = Data(OwnedProject("kotlinx.coroutines", "kotlin")) 30 | println(format.encodeToString(data)) 31 | } 32 | -------------------------------------------------------------------------------- /guide/example/example-poly-12.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly12 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.modules.* 8 | 9 | val module = SerializersModule { 10 | polymorphic(Project::class) { 11 | subclass(OwnedProject::class) 12 | } 13 | } 14 | 15 | val format = Json { serializersModule = module } 16 | 17 | @Serializable 18 | abstract class Project { 19 | abstract val name: String 20 | } 21 | 22 | @Serializable 23 | @SerialName("owned") 24 | class OwnedProject(override val name: String, val owner: String) : Project() 25 | 26 | fun main() { 27 | val data: Any = OwnedProject("kotlinx.coroutines", "kotlin") 28 | println(format.encodeToString(data)) 29 | } 30 | -------------------------------------------------------------------------------- /guide/example/example-poly-13.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly13 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.modules.* 8 | 9 | val module = SerializersModule { 10 | polymorphic(Any::class) { 11 | subclass(OwnedProject::class) 12 | } 13 | } 14 | val format = Json { serializersModule = module } 15 | 16 | @Serializable 17 | abstract class Project { 18 | abstract val name: String 19 | } 20 | 21 | @Serializable 22 | @SerialName("owned") 23 | class OwnedProject(override val name: String, val owner: String) : Project() 24 | 25 | fun main() { 26 | val data: Any = OwnedProject("kotlinx.coroutines", "kotlin") 27 | println(format.encodeToString(data)) 28 | } 29 | -------------------------------------------------------------------------------- /guide/example/example-poly-14.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly14 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.modules.* 8 | 9 | val module = SerializersModule { 10 | polymorphic(Any::class) { 11 | subclass(OwnedProject::class) 12 | } 13 | } 14 | 15 | val format = Json { serializersModule = module } 16 | 17 | @Serializable 18 | abstract class Project { 19 | abstract val name: String 20 | } 21 | 22 | @Serializable 23 | @SerialName("owned") 24 | class OwnedProject(override val name: String, val owner: String) : Project() 25 | 26 | fun main() { 27 | val data: Any = OwnedProject("kotlinx.coroutines", "kotlin") 28 | println(format.encodeToString(PolymorphicSerializer(Any::class), data)) 29 | } 30 | -------------------------------------------------------------------------------- /guide/example/example-poly-15.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly15 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.modules.* 8 | 9 | val module = SerializersModule { 10 | polymorphic(Any::class) { 11 | subclass(OwnedProject::class) 12 | } 13 | } 14 | 15 | val format = Json { serializersModule = module } 16 | 17 | interface Project { 18 | val name: String 19 | } 20 | 21 | @Serializable 22 | @SerialName("owned") 23 | class OwnedProject(override val name: String, val owner: String) : Project 24 | 25 | @Serializable 26 | class Data( 27 | @Polymorphic // the code does not compile without it 28 | val project: Any 29 | ) 30 | 31 | fun main() { 32 | val data = Data(OwnedProject("kotlinx.coroutines", "kotlin")) 33 | println(format.encodeToString(data)) 34 | } 35 | -------------------------------------------------------------------------------- /guide/example/example-poly-18.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. 2 | package example.examplePoly18 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | import kotlinx.serialization.modules.* 8 | 9 | @Serializable 10 | abstract class Project { 11 | abstract val name: String 12 | } 13 | 14 | @Serializable 15 | @SerialName("OwnedProject") 16 | data class OwnedProject(override val name: String, val owner: String) : Project() 17 | 18 | val module = SerializersModule { 19 | polymorphic(Project::class) { 20 | subclass(OwnedProject::class) 21 | } 22 | } 23 | 24 | val format = Json { serializersModule = module } 25 | 26 | fun main() { 27 | println(format.decodeFromString(""" 28 | {"type":"unknown","name":"example"} 29 | """)) 30 | } 31 | -------------------------------------------------------------------------------- /guide/example/example-readme-01.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from README.md by Knit tool. Do not edit. 2 | package example.exampleReadme01 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | data class Project(val name: String, val language: String) 9 | 10 | fun main() { 11 | // Serializing objects 12 | val data = Project("kotlinx.serialization", "Kotlin") 13 | val string = Json.encodeToString(data) 14 | println(string) // {"name":"kotlinx.serialization","language":"Kotlin"} 15 | // Deserializing back into objects 16 | val obj = Json.decodeFromString(string) 17 | println(obj) // Project(name=kotlinx.serialization, language=Kotlin) 18 | } 19 | -------------------------------------------------------------------------------- /guide/example/example-serializer-01.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from serializers.md by Knit tool. Do not edit. 2 | package example.exampleSerializer01 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | 7 | @Serializable 8 | class Color(val rgb: Int) 9 | 10 | fun main() { 11 | val green = Color(0x00ff00) 12 | println(Json.encodeToString(green)) 13 | } 14 | -------------------------------------------------------------------------------- /guide/example/example-serializer-02.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from serializers.md by Knit tool. Do not edit. 2 | package example.exampleSerializer02 3 | 4 | import kotlinx.serialization.* 5 | 6 | @Serializable 7 | @SerialName("Color") 8 | class Color(val rgb: Int) 9 | 10 | fun main() { 11 | val colorSerializer: KSerializer = Color.serializer() 12 | println(colorSerializer.descriptor) 13 | } 14 | -------------------------------------------------------------------------------- /guide/example/example-serializer-03.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from serializers.md by Knit tool. Do not edit. 2 | package example.exampleSerializer03 3 | 4 | import kotlinx.serialization.* 5 | 6 | @Serializable 7 | @SerialName("Color") 8 | class Color(val rgb: Int) 9 | 10 | @Serializable 11 | @SerialName("Box") 12 | class Box(val contents: T) 13 | 14 | fun main() { 15 | val boxedColorSerializer = Box.serializer(Color.serializer()) 16 | println(boxedColorSerializer.descriptor) 17 | } 18 | -------------------------------------------------------------------------------- /guide/example/example-serializer-04.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from serializers.md by Knit tool. Do not edit. 2 | package example.exampleSerializer04 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.builtins.* 6 | 7 | fun main() { 8 | val intSerializer: KSerializer = Int.serializer() 9 | println(intSerializer.descriptor) 10 | } 11 | -------------------------------------------------------------------------------- /guide/example/example-serializer-05.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from serializers.md by Knit tool. Do not edit. 2 | package example.exampleSerializer05 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.builtins.* 6 | 7 | fun main() { 8 | val stringListSerializer: KSerializer> = ListSerializer(String.serializer()) 9 | println(stringListSerializer.descriptor) 10 | } 11 | -------------------------------------------------------------------------------- /guide/example/example-serializer-06.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from serializers.md by Knit tool. Do not edit. 2 | package example.exampleSerializer06 3 | 4 | import kotlinx.serialization.* 5 | 6 | @Serializable 7 | @SerialName("Color") 8 | class Color(val rgb: Int) 9 | 10 | fun main() { 11 | val stringToColorMapSerializer: KSerializer> = serializer() 12 | println(stringToColorMapSerializer.descriptor) 13 | } 14 | -------------------------------------------------------------------------------- /guide/example/example-serializer-21.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from serializers.md by Knit tool. Do not edit. 2 | package example.exampleSerializer21 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | import kotlinx.serialization.encoding.* 7 | import kotlinx.serialization.descriptors.* 8 | 9 | import java.util.Date 10 | import java.text.SimpleDateFormat 11 | 12 | @Serializable 13 | class ProgrammingLanguage( 14 | val name: String, 15 | @Contextual 16 | val stableReleaseDate: Date 17 | ) 18 | 19 | fun main() { 20 | val data = ProgrammingLanguage("Kotlin", SimpleDateFormat("yyyy-MM-ddX").parse("2016-02-15+00")) 21 | println(Json.encodeToString(data)) 22 | } 23 | -------------------------------------------------------------------------------- /guide/example/example-serializer-23.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from serializers.md by Knit tool. Do not edit. 2 | package example.exampleSerializer23 3 | 4 | import kotlinx.serialization.* 5 | import kotlinx.serialization.json.* 6 | import kotlinx.serialization.encoding.* 7 | import kotlinx.serialization.descriptors.* 8 | 9 | // NOT @Serializable 10 | class Project(val name: String, val language: String) 11 | 12 | @OptIn(ExperimentalSerializationApi::class) 13 | @Serializer(forClass = Project::class) 14 | object ProjectSerializer 15 | 16 | fun main() { 17 | val data = Project("kotlinx.serialization", "Kotlin") 18 | println(Json.encodeToString(ProjectSerializer, data)) 19 | } 20 | -------------------------------------------------------------------------------- /guide/test/ReadmeTest.kt: -------------------------------------------------------------------------------- 1 | // This file was automatically generated from README.md by Knit tool. Do not edit. 2 | package example.test 3 | 4 | import org.junit.Test 5 | import kotlinx.knit.test.* 6 | 7 | class ReadmeTest { 8 | @Test 9 | fun testExampleReadme01() { 10 | captureOutput("ExampleReadme01") { example.exampleReadme01.main() }.verifyOutputLines( 11 | "{\"name\":\"kotlinx.serialization\",\"language\":\"Kotlin\"}", 12 | "Project(name=kotlinx.serialization, language=Kotlin)" 13 | ) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration-test/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | # 4 | 5 | mainKotlinVersion=2.1.20 6 | mainLibVersion=1.8.2-SNAPSHOT 7 | 8 | kotlin.code.style=official 9 | 10 | gradle_node_version = 1.2.0 11 | node_version = 8.9.3 12 | npm_version = 5.7.1 13 | mocha_version = 4.1.0 14 | mocha_teamcity_reporter_version = 2.2.2 15 | source_map_support_version = 0.5.3 16 | 17 | kapt.use.k2=true 18 | 19 | org.gradle.kotlin.dsl.allWarningsAsErrors=true 20 | 21 | # Uncommend & insert path to local Native distribution if you want to test with SNAPSHOT compiler 22 | #kotlin.native.home= 23 | 24 | #org.jetbrains.kotlin.native.jvmArgs=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5007 25 | -------------------------------------------------------------------------------- /integration-test/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/kotlinx.serialization/4667a1891a925dc9e3e10490c274a875b0be4da6/integration-test/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /integration-test/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /integration-test/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | resolutionStrategy { 3 | val mainKotlinVersion: String by settings 4 | eachPlugin { 5 | if (requested.id.id == "org.jetbrains.kotlin.multiplatform") { 6 | useVersion("$mainKotlinVersion") 7 | } 8 | if (requested.id.id == "org.jetbrains.kotlin.kapt") { 9 | useVersion("$mainKotlinVersion") 10 | } 11 | if (requested.id.id == "org.jetbrains.kotlin.plugin.serialization") { 12 | useVersion("$mainKotlinVersion") 13 | } 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | maven("https://plugins.gradle.org/m2/") 20 | maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") 21 | mavenLocal() 22 | } 23 | } 24 | 25 | rootProject.name = "kotlinx-serialization-integration-test" 26 | -------------------------------------------------------------------------------- /integration-test/src/commonMain/kotlin/sample/GeoCoordinate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package sample 6 | 7 | import kotlinx.serialization.Serializable 8 | 9 | @Serializable 10 | data class GeoCoordinate( 11 | val latitude: Double = 0.0, 12 | val longitude: Double = 0.0 13 | ) { 14 | 15 | init { 16 | require(latitude >= 0) { "latitude must be non-negative" } 17 | require(longitude >= 0) { "longitude must be non-negative" } 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /integration-test/src/commonMain/kotlin/sample/Sample.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package sample 6 | 7 | expect object Platform { 8 | val name: String 9 | } 10 | 11 | fun hello(): String = "Hello from ${Platform.name}" 12 | -------------------------------------------------------------------------------- /integration-test/src/jsMain/kotlin/sample/SampleJs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 JetBrains s.r.o. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample 18 | 19 | actual object Platform { 20 | actual val name: String = "JS" 21 | } 22 | -------------------------------------------------------------------------------- /integration-test/src/jsTest/kotlin/sample/SampleTestsJS.kt: -------------------------------------------------------------------------------- 1 | package sample 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertTrue 5 | 6 | class SampleTestsJS { 7 | @Test 8 | fun testHello() { 9 | assertTrue("JS" in hello()) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-test/src/jvmMain/kotlin/sample/SampleJvm.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 JetBrains s.r.o. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample 18 | 19 | actual object Platform { 20 | actual val name: String = "JVM" 21 | } 22 | -------------------------------------------------------------------------------- /integration-test/src/jvmTest/kotlin/sample/SampleTestsJVM.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 | */ 4 | 5 | package sample 6 | 7 | import kotlinx.serialization.* 8 | import kotlinx.serialization.builtins.* 9 | import kotlin.test.* 10 | 11 | class SampleTestsJVM { 12 | @Test 13 | fun testHello() { 14 | assertTrue("JVM" in hello()) 15 | } 16 | 17 | @Test 18 | @OptIn(ExperimentalSerializationApi::class) 19 | fun kindSimpleName() { 20 | val kind = Int.serializer().descriptor.kind 21 | val name = kind.toString() 22 | assertEquals("INT", name) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /integration-test/src/nativeMain/kotlin/sample/SampleMacos.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 JetBrains s.r.o. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample 18 | 19 | actual object Platform { 20 | actual val name: String = "Native" 21 | } 22 | -------------------------------------------------------------------------------- /integration-test/src/nativeTest/kotlin/sample/SampleTestsNative.kt: -------------------------------------------------------------------------------- 1 | package sample 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertTrue 5 | 6 | class SampleTestsNative { 7 | @Test 8 | fun testHello() { 9 | assertTrue("Native" in hello()) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-test/src/wasmJsMain/kotlin/sample/SampleWasm.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 JetBrains s.r.o. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample 18 | 19 | actual object Platform { 20 | actual val name: String = "WasmJs" 21 | } 22 | -------------------------------------------------------------------------------- /integration-test/src/wasmJsTest/kotlin/sample/SampleTestsWasm.kt: -------------------------------------------------------------------------------- 1 | package sample 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertTrue 5 | 6 | class SampleTestsWasm { 7 | @Test 8 | fun testHello() { 9 | assertTrue("WasmJs" in hello()) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration-test/src/wasmWasiMain/kotlin/sample/SampleWasm.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 JetBrains s.r.o. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample 18 | 19 | actual object Platform { 20 | actual val name: String = "WasmWasi" 21 | } 22 | -------------------------------------------------------------------------------- /integration-test/src/wasmWasiTest/kotlin/sample/SampleTestsWasm.kt: -------------------------------------------------------------------------------- 1 | package sample 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertTrue 5 | 6 | class SampleTestsWasm { 7 | @Test 8 | fun testHello() { 9 | assertTrue("WasmWasi" in hello()) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /knit.properties: -------------------------------------------------------------------------------- 1 | knit.dir=guide/example/ 2 | knit.package=example 3 | 4 | test.dir=guide/test/ 5 | test.package=example.test 6 | -------------------------------------------------------------------------------- /license/LICENSE.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 JetBrains s.r.o. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /license/NOTICE.txt: -------------------------------------------------------------------------------- 1 | ========================================================================= 2 | == NOTICE file corresponding to the section 4 d of == 3 | == the Apache License, Version 2.0, == 4 | == in this case for the kotlix.serialization library. == 5 | ========================================================================= 6 | 7 | kotlinx.serialization library. 8 | Copyright 2017-2019 JetBrains s.r.o and respective authors and developers 9 | --------------------------------------------------------------------------------