├── .github ├── stale.yml └── workflows │ ├── master.yml │ ├── pr_scala_2.yml │ ├── pr_scala_3.yml │ ├── release.yml │ └── release_40x.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── avro4s-cats └── src │ └── main │ └── scala │ └── com │ └── sksamuel │ └── avro4s │ └── cats │ └── package.scala ├── avro4s-core └── src │ ├── main │ └── scala │ │ └── com │ │ └── sksamuel │ │ └── avro4s │ │ ├── AvroBinaryInputStream.scala │ │ ├── AvroBinaryOutputStream.scala │ │ ├── AvroDataInputStream.scala │ │ ├── AvroDataOutputStream.scala │ │ ├── AvroInputStream.scala │ │ ├── AvroJavaEnumDefault.java │ │ ├── AvroJavaName.java │ │ ├── AvroJavaNamespace.java │ │ ├── AvroJavaProp.java │ │ ├── AvroJsonInputStream.scala │ │ ├── AvroOutputStream.scala │ │ ├── AvroSchema.scala │ │ ├── Codec.scala │ │ ├── CustomDefaults.scala │ │ ├── Decoder.scala │ │ ├── DefaultAwareDatumReader.scala │ │ ├── DefaultAwareGenericData.scala │ │ ├── DefaultResolver.scala │ │ ├── Encoder.scala │ │ ├── FieldMapper.scala │ │ ├── FromRecord.scala │ │ ├── ImmutableRecord.scala │ │ ├── RecordFields.scala │ │ ├── RecordFormat.scala │ │ ├── Records.scala │ │ ├── ScalaEnums.scala │ │ ├── SchemaFor.scala │ │ ├── ShapelessCoproducts.scala │ │ ├── SparkSchemas.scala │ │ ├── ToRecord.scala │ │ ├── TypeGuardedDecoding.scala │ │ ├── ValueTypes.scala │ │ ├── annotations.scala │ │ ├── avroutils │ │ ├── AvroSchemaMerge.scala │ │ ├── ByteBufferHelper.scala │ │ ├── EnumHelpers.scala │ │ └── SchemaHelper.scala │ │ ├── decoders │ │ ├── bigdecimals.scala │ │ ├── bytes.scala │ │ ├── collections.scala │ │ ├── eithers.scala │ │ ├── magnolia.scala │ │ ├── options.scala │ │ ├── primitives.scala │ │ ├── records.scala │ │ ├── sealedtraits.scala │ │ ├── strings.scala │ │ ├── temporal.scala │ │ └── unions.scala │ │ ├── encoders │ │ ├── bigdecimals.scala │ │ ├── bytes.scala │ │ ├── collections.scala │ │ ├── eithers.scala │ │ ├── magnolia.scala │ │ ├── options.scala │ │ ├── primitives.scala │ │ ├── records.scala │ │ ├── sealedtraits.scala │ │ ├── strings.scala │ │ ├── temporal.scala │ │ ├── tuples.scala │ │ └── unions.scala │ │ ├── exceptions.scala │ │ ├── format.scala │ │ ├── schemas │ │ ├── bigdecimals.scala │ │ ├── bytes.scala │ │ ├── collections.scala │ │ ├── eithers.scala │ │ ├── enums.scala │ │ ├── logicals.scala │ │ ├── magnolia.scala │ │ ├── options.scala │ │ ├── primitives.scala │ │ ├── records.scala │ │ ├── scalaenums.scala │ │ ├── sealedtraits.scala │ │ ├── strings.scala │ │ ├── temporal.scala │ │ ├── tuples.scala │ │ ├── unions.scala │ │ └── valuetypes.scala │ │ └── typeutils │ │ ├── Annotations.scala │ │ ├── DatatypeShape.scala │ │ ├── EnumTypes.scala │ │ ├── Names.scala │ │ └── Subtypes.scala │ └── test │ ├── resources │ ├── aliases_on_fields.json │ ├── aliases_on_types.json │ ├── aliases_on_types_multiple.json │ ├── array.avsc │ ├── array_of_maps.json │ ├── arrayrecords.json │ ├── avro_error.json │ ├── avro_error_field.json │ ├── avro_name_class.json │ ├── avro_name_field.json │ ├── avro_name_field_mapping.json │ ├── avro_name_java_enum.json │ ├── avro_name_nested_java_enum.json │ ├── avro_name_on_type_arg.json │ ├── avro_name_sealed_trait.json │ ├── avro_name_sealed_trait_symbol.json │ ├── avro_nodefault.json │ ├── avro_sort_priority_enum.json │ ├── avro_sort_priority_union.json │ ├── avro_sort_priority_union_with_default.json │ ├── avro_union_position_enum.json │ ├── avro_union_position_union.json │ ├── bigdecimal-scale-and-precision.json │ ├── bigdecimal.json │ ├── bigdecimal_as_fixed.json │ ├── bigdecimal_as_string.json │ ├── bigdecimal_bytes.avsc │ ├── bigdecimal_default.json │ ├── bigdecimal_nested_default.json │ ├── bigdecimal_option.json │ ├── bigdecimal_seq.json │ ├── bigdecimal_seq_option.json │ ├── boolean.avsc │ ├── byte_array.json │ ├── bytebuffer.json │ ├── bytes.avsc │ ├── case_class_default_values.json │ ├── case_object_default_values.json │ ├── class_of_list_of_maps.json │ ├── class_with_list_of_maps.json │ ├── coproduct.json │ ├── coproduct_of_coproducts.json │ ├── coproduct_option.json │ ├── coproduct_with_default.json │ ├── date.json │ ├── deeply_nested_generic_with_value_type.json │ ├── deeply_nested_generics.json │ ├── deepnested.json │ ├── default_values_boolean.json │ ├── default_values_double.json │ ├── default_values_float.json │ ├── default_values_instant.json │ ├── default_values_int.json │ ├── default_values_long.json │ ├── default_values_optional_union.json │ ├── default_values_string.json │ ├── defaultvalues.json │ ├── doc_annotation_class.json │ ├── doc_annotation_field.json │ ├── doc_annotation_field_struct.json │ ├── doc_annotation_value_type.json │ ├── doc_field_regular_case_class.json │ ├── double.json │ ├── either.json │ ├── either_record.json │ ├── either_record_with_avro_namespace.json │ ├── eithers.avro │ ├── field_mapper_default.json │ ├── field_mapper_pascal.json │ ├── field_mapper_snake.json │ ├── fixed_string.json │ ├── fixed_string_top_level_value_type.json │ ├── fixed_string_value_type_as_field.json │ ├── float.avsc │ ├── gameofthrones.avsc │ ├── generic.json │ ├── genericSchema.avsc │ ├── generic_disabled.json │ ├── generic_int.json │ ├── generic_string.json │ ├── github │ │ ├── github_318.json │ │ ├── github_330.json │ │ ├── github_331.json │ │ ├── github_346.json │ │ └── github_389.json │ ├── github12.json │ ├── github187.json │ ├── github254_a.json │ ├── github254_b.json │ ├── github254_lista.json │ ├── github292.json │ ├── github295.json │ ├── github69.json │ ├── instant.json │ ├── integer.avsc │ ├── java_enum.json │ ├── java_enum_option.json │ ├── java_enum_top_level.json │ ├── java_enum_top_level_with_default.json │ ├── java_string.json │ ├── list.json │ ├── list_of_maps.json │ ├── listrecords.json │ ├── local_class_namespace.json │ ├── localdate.json │ ├── localdatetime.json │ ├── localtime.json │ ├── long.json │ ├── map_int.json │ ├── map_option.json │ ├── map_record.json │ ├── map_seq_nested.json │ ├── map_seq_string.json │ ├── map_string.json │ ├── namespace.avsc │ ├── namespace_class_adt_field.avsc │ ├── namespace_empty.json │ ├── namespace_enum_class_level.json │ ├── namespace_enum_field_level.json │ ├── namespace_enum_trait_level.json │ ├── naming_strategy_lisp.json │ ├── nested.json │ ├── nested_adts.json │ ├── nested_in_uppercase_pkg.json │ ├── nested_multiple.json │ ├── none.json │ ├── object_namespaces.json │ ├── object_namespaces_local.json │ ├── option.json │ ├── option_default_value.json │ ├── option_either.json │ ├── option_enum.json │ ├── option_from_null_default.json │ ├── option_sealed_trait.json │ ├── optional_default_values.json │ ├── optional_sealed_trait_enum.json │ ├── optional_union.json │ ├── options.avro │ ├── painters.avro │ ├── props_annotation_class.json │ ├── props_annotation_field.json │ ├── props_annotation_json_field.json │ ├── props_annotation_scala_enum.json │ ├── scala3_enum.json │ ├── schema_override_basic.json │ ├── schema_override_complex.json │ ├── schema_override_top_level_value_type.json │ ├── schema_override_value_type.json │ ├── scoped_implicits.avsc │ ├── sealed_trait_enum_no_default.json │ ├── sealed_trait_of_nested_objects.json │ ├── sealed_trait_of_objects.json │ ├── sealed_traits.json │ ├── seq.avsc │ ├── seq2.avsc │ ├── seq3.avsc │ ├── seq4.avsc │ ├── seq_of_maps.json │ ├── seq_tuple2.json │ ├── seq_tuple3.json │ ├── seqofmaps.avsc │ ├── seqrecords.json │ ├── setdoubles.json │ ├── setrecords.json │ ├── setstrings.json │ ├── string.json │ ├── timestamp.json │ ├── top_level_boolean.json │ ├── top_level_byte_array.json │ ├── top_level_bytebuffer.json │ ├── top_level_class_namespace.json │ ├── top_level_double.json │ ├── top_level_float.json │ ├── top_level_integer.json │ ├── top_level_list_int.json │ ├── top_level_long.json │ ├── top_level_object_namespace.json │ ├── top_level_package_object_namespace.json │ ├── top_level_sealed_trait.json │ ├── top_level_seq_double.json │ ├── top_level_set_boolean.json │ ├── top_level_string.json │ ├── top_level_vector_string.json │ ├── trait_subtypes_duplicate_fields.json │ ├── trait_subtypes_duplicate_fields_same_type.json │ ├── traits.avsc │ ├── transient.json │ ├── tuple2.json │ ├── tuple3.json │ ├── tuple4.json │ ├── tuple5.json │ ├── universe.json │ ├── utf8.json │ ├── uuid.json │ ├── uuid_default.json │ ├── uuid_option.json │ ├── uuid_seq.json │ ├── value_class_nested.json │ ├── value_class_top_level.json │ ├── vector_of_maps.json │ ├── vector_prim.json │ └── vector_records.json │ └── scala │ └── com │ └── sksamuel │ └── avro4s │ ├── Recursive.scala │ ├── SchemaForUtf8Test.scala │ ├── examples │ ├── Examples.scala │ ├── ReadMeExamples.scala │ ├── TraitObjectEnumerationExample.scala │ └── UppercasePkg │ │ └── ClassInUppercasePackage.scala │ ├── github │ ├── Github202.scala │ ├── Github254.scala │ ├── Github265.scala │ ├── Github273.scala │ ├── Github284.scala │ ├── Github292.scala │ ├── Github295.scala │ ├── Github318.scala │ ├── Github396.scala │ ├── Github408.scala │ ├── Github411.scala │ ├── Github415.scala │ ├── Github587.scala │ ├── GithubIssue110.scala │ ├── GithubIssue12.scala │ ├── GithubIssue180.scala │ ├── GithubIssue187And152.scala │ ├── GithubIssue191.scala │ ├── GithubIssue193.scala │ ├── GithubIssue205.scala │ ├── GithubIssue234.scala │ ├── GithubIssue235.scala │ ├── GithubIssue247.scala │ ├── GithubIssue260.scala │ ├── GithubIssue281.scala │ ├── GithubIssue330.scala │ ├── GithubIssue331.scala │ ├── GithubIssue346.scala │ ├── GithubIssue387.scala │ ├── GithubIssue389.scala │ ├── GithubIssue432.scala │ ├── GithubIssue484.scala │ ├── GithubIssue485.scala │ ├── GithubIssue510.scala │ ├── GithubIssue545.scala │ └── GithubIssue69.scala │ ├── record │ ├── BigDecimalRoundTrip.scala │ ├── FromRecordTest.scala │ ├── LocalDateTimeRoundTrip.scala │ ├── ToRecordTest.scala │ ├── TypeGuardedDecoderTest.scala │ ├── decoder │ │ ├── ArrayDecoderTest.scala │ │ ├── AvroNameDecoderTest.scala │ │ ├── BasicDecoderTest.scala │ │ ├── BigDecimalDecoderTest.scala │ │ ├── ByteArrayDecoderTest.scala │ │ ├── CoproductDecoderTest.scala │ │ ├── DateDecoderTest.scala │ │ ├── DecoderTypeclassOverrideTest.scala │ │ ├── EitherDecoderTest.scala │ │ ├── EnumDecoderTest.scala │ │ ├── FieldMapperDecoderTest.scala │ │ ├── FixedDecoderTest.scala │ │ ├── MapDecoderTest.scala │ │ ├── OptionDecoderTest.scala │ │ ├── ReorderFieldsDecoderTest.scala │ │ ├── Scala3EnumDecoderTest.scala │ │ ├── SchemaEvolutionTest.scala │ │ ├── SealedTraitDecoderTest.scala │ │ ├── StringDecoderTest.scala │ │ ├── StructDecoderTest.scala │ │ ├── TransientDecoderTest.scala │ │ ├── TupleDecoderTest.scala │ │ ├── UUIDDecoderTest.scala │ │ └── ValueTypeDecoderTest.scala │ └── encoder │ │ ├── ArrayEncoderTest.scala │ │ ├── AvroNameEncoderTest.scala │ │ ├── AvroTransientEncoderTest.scala │ │ ├── BasicEncoderTest.scala │ │ ├── BigDecimalEncoderTest.scala │ │ ├── ByteArrayEncoderTest.scala │ │ ├── CoproductEncoderTest.scala │ │ ├── DateEncoderTest.scala │ │ ├── EitherEncoderTest.scala │ │ ├── EncoderTypeclassOverrideTest.scala │ │ ├── EnumEncoderTest.scala │ │ ├── FieldMapperEncoderTest.scala │ │ ├── FixedEncoderTest.scala │ │ ├── MapEncoderTest.scala │ │ ├── NestedStructEncoderTest.scala │ │ ├── OptionEncoderTest.scala │ │ ├── ReorderFieldsEncoderTest.scala │ │ ├── Scala3EnumEncoderTest.scala │ │ ├── SealedTraitEncoderTest.scala │ │ ├── StringEncoderTest.scala │ │ ├── StructEncoderTest.scala │ │ ├── TupleEncoderTest.scala │ │ ├── UUIDEncoderTest.scala │ │ └── ValueTypeEncoderTest.scala │ ├── schema │ ├── ArraySchemaTest.scala │ ├── AvroAliasSchemaTest.scala │ ├── AvroDocSchemaTest.scala │ ├── AvroErrorSchemaTest.scala │ ├── AvroFixedSchemaTest.scala │ ├── AvroNameSchemaTest.scala │ ├── AvroNamespaceSchemaTest.scala │ ├── AvroNoDefaultTest.scala │ ├── AvroPropSchemaTest.scala │ ├── AvroSchemaMergeTest.scala │ ├── AvroSortPrioritySchemaTest.scala │ ├── AvroUnionPositionSchemaTest.scala │ ├── BasicSchemasTest.scala │ ├── BigDecimalSchemaTest.scala │ ├── ByteArraySchemaTest.scala │ ├── CoproductSchemaTest.scala │ ├── DateSchemaTest.scala │ ├── DefaultValueRecordTest.scala │ ├── DefaultValueSchemaTest.scala │ ├── EitherSchemaTest.scala │ ├── EnumSchemaCompatibilityTest.scala │ ├── EnumSchemaTest.scala │ ├── FieldMapperFieldTest.scala │ ├── GenericSchemaTest.scala │ ├── MapSchemaTest.scala │ ├── MyJavaEnum.java │ ├── NamespaceSchemaTest.scala │ ├── OptionSchemaTest.scala │ ├── PrimitiveSchemaTest.scala │ ├── SchemaForTypeclassOverrideTest.scala │ ├── SealedTraitSchemaTest.scala │ ├── StringSchemasTest.scala │ ├── TransientSchemaTest.scala │ ├── TupleSchemaTest.scala │ ├── UUIDSchemaTest.scala │ ├── UtfSchemaTest.scala │ ├── ValueTypeSchemaTest.scala │ ├── Wine.java │ ├── WineWithAnnotations.java │ └── package.scala │ └── streams │ ├── input │ ├── BasicInputStreamTest.scala │ ├── BigDecimalInputStreamTest.scala │ ├── CollectionsInputStreamTest.scala │ ├── EitherInputStreamTest.scala │ ├── EnumInputStreamTest.scala │ └── InputStreamTest.scala │ └── output │ ├── AvroDataOutputStreamCodecTest.scala │ ├── BasicOutputStreamTest.scala │ ├── BigDecimalOutputStreamTest.scala │ ├── BinaryOutputStreamTest.scala │ ├── CollectionsOutputStreamTest.scala │ ├── EitherOutputStreamTest.scala │ ├── EnumOutputStreamTest.scala │ ├── OptionOutputStreamTest.scala │ ├── OutputStreamTest.scala │ ├── Style.java │ ├── UUIDOutputStreamTest.scala │ └── ValueTypeOutputStreamTest.scala ├── avro4s-kafka └── src │ ├── main │ └── scala │ │ └── com │ │ └── sksamuel │ │ └── avro4s │ │ └── kafka │ │ └── GenericSerde.scala │ └── test │ └── scala │ └── com │ └── sksamuel │ └── avro4s │ └── kafka │ └── GenericSerdeTest.scala ├── benchmarks.txt ├── benchmarks └── src │ └── main │ ├── java │ └── benchmarks │ │ └── record │ │ └── generated │ │ ├── AttributeValue │ │ ├── Empty.java │ │ ├── Invalid.java │ │ └── ValidInt.java │ │ └── RecordWithUnionAndTypeField.java │ └── scala │ └── benchmarks │ ├── BenchmarkHelpers.scala │ ├── CommonParams.scala │ ├── Decoding.scala │ ├── Encoding.scala │ ├── handrolled_codecs │ └── package.scala │ └── record │ ├── Attributes.scala │ └── Records.scala ├── build.sbt ├── logo.png ├── project ├── Build.scala ├── build.properties └── plugins.sbt └── run_benchmarks.sh /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | # Label to use when marking an issue as stale 10 | staleLabel: abandoned 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: > 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | # Comment to post when closing a stale issue. Set to `false` to disable 17 | closeComment: false 18 | -------------------------------------------------------------------------------- /.github/workflows/master.yml: -------------------------------------------------------------------------------- 1 | name: master 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'doc/**' 7 | - 'docs/**' 8 | - '*.md' 9 | - '*.yml' 10 | branches: 11 | - master 12 | - release/5* 13 | 14 | jobs: 15 | scala_3_0: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: checkout the repo 19 | uses: actions/checkout@v2 20 | with: 21 | fetch-depth: 0 22 | 23 | - uses: coursier/setup-action@v1 24 | with: 25 | apps: sbt 26 | jvm: temurin:11 27 | 28 | - name: run tests 29 | run: sbt test 30 | 31 | - name: Import GPG key 32 | id: import_gpg 33 | uses: crazy-max/ghaction-import-gpg@v3 34 | with: 35 | gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} 36 | passphrase: ${{ secrets.PGP_PASSPHRASE }} 37 | 38 | - name: GPG user IDs 39 | run: | 40 | echo "fingerprint: ${{ steps.import_gpg.outputs.fingerprint }}" 41 | echo "keyid: ${{ steps.import_gpg.outputs.keyid }}" 42 | echo "name: ${{ steps.import_gpg.outputs.name }}" 43 | echo "email: ${{ steps.import_gpg.outputs.email }}" 44 | 45 | - name: publish snapshot 46 | run: sbt publish 47 | env: 48 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 49 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} -------------------------------------------------------------------------------- /.github/workflows/pr_scala_2.yml: -------------------------------------------------------------------------------- 1 | name: pr_scala_2 2 | 3 | on: 4 | pull_request: 5 | paths-ignore: 6 | - 'doc/**' 7 | - 'docs/**' 8 | - '*.md' 9 | branches: 10 | - scala2/* 11 | 12 | jobs: 13 | scala-2_12: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: checkout the repo 17 | uses: actions/checkout@v2 18 | with: 19 | fetch-depth: 0 20 | 21 | - name: Set up SBT 22 | uses: coursier/setup-action@v1 23 | with: 24 | apps: sbt 25 | jvm: temurin:11 26 | 27 | - name: run tests 28 | run: sbt ++2.12.10 test 29 | 30 | scala-2_13: 31 | runs-on: ubuntu-latest 32 | steps: 33 | - name: checkout the repo 34 | uses: actions/checkout@v2 35 | with: 36 | fetch-depth: 0 37 | 38 | - name: Set up SBT 39 | uses: coursier/setup-action@v1 40 | with: 41 | apps: sbt 42 | jvm: temurin:11 43 | 44 | - name: run tests 45 | run: sbt ++2.13.3 test -------------------------------------------------------------------------------- /.github/workflows/pr_scala_3.yml: -------------------------------------------------------------------------------- 1 | name: pr_scala_3 2 | 3 | on: 4 | pull_request: 5 | paths-ignore: 6 | - 'doc/**' 7 | - 'docs/**' 8 | - '*.md' 9 | branches: 10 | - master 11 | 12 | jobs: 13 | scala_3_0: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: checkout the repo 17 | uses: actions/checkout@v2 18 | with: 19 | fetch-depth: 0 20 | 21 | - name: setup sbt 22 | uses: coursier/setup-action@v1 23 | with: 24 | apps: sbt 25 | jvm: temurin:11 26 | 27 | - name: run tests 28 | run: sbt test 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | 4 | # sbt specific 5 | .cache 6 | .history 7 | .lib/ 8 | dist/* 9 | target/ 10 | lib_managed/ 11 | src_managed/ 12 | project/boot/ 13 | project/plugins/project/ 14 | 15 | # Scala-IDE specific 16 | .scala_dependencies 17 | .worksheet 18 | 19 | credentials.sbt 20 | .idea 21 | *.iml 22 | 23 | universe.avro 24 | sbt.json -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/AvroBinaryOutputStream.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.Schema 4 | 5 | import java.io.OutputStream 6 | import org.apache.avro.generic.GenericDatumWriter 7 | 8 | class AvroBinaryOutputStream[T](schema: Schema, 9 | os: OutputStream, 10 | serializer: org.apache.avro.io.Encoder) 11 | (using encoder: Encoder[T]) extends AvroOutputStream[T] { 12 | 13 | private val datumWriter = new GenericDatumWriter[Any](schema) 14 | private val encodeT = encoder.encode(schema) 15 | 16 | override def close(): Unit = { 17 | flush() 18 | os.close() 19 | } 20 | 21 | override def write(t: T): Unit = { 22 | val datum = encodeT(t) 23 | datumWriter.write(datum, serializer) 24 | } 25 | 26 | override def flush(): Unit = serializer.flush() 27 | override def fSync(): Unit = () 28 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/AvroJavaEnumDefault.java: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Specifies a java enum's default value when avro4s converts the enum to an AVRO schema. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ ElementType.FIELD }) 13 | public @interface AvroJavaEnumDefault {} 14 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/AvroJavaName.java: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Overrides a java type's name when avro4s converts the type to an AVRO schema. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ ElementType.TYPE, ElementType.FIELD }) 13 | public @interface AvroJavaName { 14 | String value(); 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/AvroJavaNamespace.java: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Overrides a java type's namespace when avro4s converts the type to an AVRO schema. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ ElementType.TYPE }) 13 | public @interface AvroJavaNamespace { 14 | String value(); 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/AvroJavaProp.java: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Adds an addition property to a java type when avro4s converts the type to an AVRO schema. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ ElementType.TYPE }) 13 | public @interface AvroJavaProp { 14 | String key(); 15 | String value(); 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/AvroJsonInputStream.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.Schema 4 | import org.apache.avro.generic.GenericDatumReader 5 | import org.apache.avro.io.DecoderFactory 6 | 7 | import java.io.InputStream 8 | import scala.util.Try 9 | 10 | final case class AvroJsonInputStream[T](in: InputStream, 11 | writerSchema: Schema) 12 | (using decoder: Decoder[T]) extends AvroInputStream[T] { 13 | 14 | private val datumReader = new GenericDatumReader[AnyRef](writerSchema) 15 | private val deserializer = DecoderFactory.get.jsonDecoder(writerSchema, in) 16 | private val decodeT = decoder.decode(writerSchema) 17 | 18 | private def next = Try { 19 | datumReader.read(null, deserializer) 20 | } 21 | 22 | def iterator: Iterator[T] = Iterator.continually(next) 23 | .takeWhile(_.isSuccess) 24 | .map(_.get) 25 | .map(decodeT.apply(_)) 26 | 27 | def tryIterator: Iterator[Try[T]] = Iterator.continually(next) 28 | .takeWhile(_.isSuccess) 29 | .map(_.get) 30 | .map(record => Try(decodeT.apply(record))) 31 | 32 | def singleEntity: Try[T] = next.map(decodeT.apply(_)) 33 | 34 | override def close(): Unit = in.close() 35 | } 36 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/AvroSchema.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.Schema 4 | 5 | /** 6 | * Creates an Avro Schema for an arbitrary type T. 7 | * 8 | * This type is called [[AvroSchema]] and not just [[Schema]] to facilitate easy 9 | * importing when mixing with [[org.apache.avro.Schema]]. 10 | */ 11 | object AvroSchema { 12 | 13 | /** 14 | * Generates an [[org.apache.avro.Schema]] for a type T using default configuration. 15 | * 16 | * Requires an instance of [[SchemaFor]] which is usually 17 | * generated by the avro4s macros. 18 | */ 19 | def apply[T](using schemaFor: SchemaFor[T]): Schema = schemaFor.schema 20 | } 21 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/Decoder.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import com.sksamuel.avro4s.decoders.{ByteDecoders, CollectionDecoders, EitherDecoders, MagnoliaDerivedDecoder, OptionDecoders, PrimitiveDecoders, StringDecoders, TemporalDecoders} 4 | import org.apache.avro.Schema 5 | 6 | /** 7 | * A [[Decoder]] is used to convert an Avro value, such as a GenericRecord, 8 | * SpecificRecord, GenericFixed, EnumSymbol, or a basic type, into a 9 | * specified Scala type. 10 | * 11 | * For example, a Decoder[String] would convert an input into a plain Java String. 12 | * 13 | * Another example, a decoder for Option[String] would handle inputs of null 14 | * by emitting a None, and a non-null input by emitting a String wrapped in a Some. 15 | */ 16 | trait Decoder[T] extends Serializable { 17 | self => 18 | 19 | def decode(schema: Schema): Any => T 20 | 21 | final def map[U](f: T => U): Decoder[U] = new Decoder[U] { 22 | override def decode(schema: Schema): Any => U = { input => 23 | f(self.decode(schema).apply(input)) 24 | } 25 | } 26 | } 27 | 28 | object Decoder 29 | extends PrimitiveDecoders 30 | with BigDecimalDecoders 31 | with ByteDecoders 32 | with CollectionDecoders 33 | with EitherDecoders 34 | with OptionDecoders 35 | with StringDecoders 36 | with TemporalDecoders 37 | with MagnoliaDerivedDecoder { 38 | def apply[T](using decoder: Decoder[T]): Decoder[T] = decoder 39 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/DefaultAwareDatumReader.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.generic.GenericDatumReader 4 | import org.apache.avro.io.ResolvingDecoder 5 | import org.apache.avro.{AvroTypeException, Schema} 6 | 7 | class DefaultAwareDatumReader[T](writer: Schema, reader: Schema) 8 | extends GenericDatumReader[T](writer, reader, new DefaultAwareGenericData) { 9 | override def readField(r: scala.Any, 10 | f: Schema.Field, 11 | oldDatum: scala.Any, 12 | in: ResolvingDecoder, 13 | state: scala.Any): Unit = { 14 | try { 15 | super.readField(r, f, oldDatum, in, state) 16 | } catch { 17 | case t: AvroTypeException => 18 | if (f.defaultVal == null) throw t else getData.setField(r, f.name, f.pos, f.defaultVal) 19 | } 20 | } 21 | } 22 | 23 | object DefaultAwareDatumReader { 24 | def apply[T](writerSchema: Schema): DefaultAwareDatumReader[T] = new DefaultAwareDatumReader[T](writerSchema, writerSchema) 25 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/DefaultAwareGenericData.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.Schema 4 | import org.apache.avro.generic.GenericData 5 | 6 | class DefaultAwareGenericData extends GenericData { 7 | override def newRecord(old: scala.Any, schema: Schema): AnyRef = { 8 | import scala.collection.JavaConverters._ 9 | val record = new GenericData.Record(schema) 10 | schema.getFields.asScala.foreach { field => 11 | record.put(field.name, field.defaultVal) 12 | } 13 | record 14 | } 15 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/FromRecord.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.Schema 4 | import org.apache.avro.generic.IndexedRecord 5 | 6 | /** 7 | * Converts from an Avro [[IndexedRecord]] into instances of T. 8 | */ 9 | trait FromRecord[T] extends Serializable { 10 | def from(record: IndexedRecord): T 11 | } 12 | 13 | object FromRecord { 14 | def apply[T](schema: Schema)(using decoder: Decoder[T]): FromRecord[T] = new FromRecord[T] { 15 | override def from(record: IndexedRecord): T = decoder.decode(schema).apply(record) 16 | } 17 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/ImmutableRecord.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.Schema 4 | import org.apache.avro.generic.GenericRecord 5 | import org.apache.avro.specific.SpecificRecord 6 | 7 | /** 8 | * An implementation of org.apache.avro.generic.GenericContainer that is both a 9 | * GenericRecord and a SpecificRecord. 10 | */ 11 | trait Record extends GenericRecord with SpecificRecord 12 | 13 | case class ImmutableRecord(schema: Schema, values: Seq[Any]) extends Record { 14 | 15 | require(schema.getType == Schema.Type.RECORD, "Cannot create an ImmutableRecord with a schema that is not a RECORD") 16 | require(schema.getFields.size == values.size, 17 | s"Schema field size (${schema.getFields.size}) and value Seq size (${values.size}) must match") 18 | 19 | override def put(key: String, v: scala.Any): Unit = throw new UnsupportedOperationException("This implementation of Record is immutable") 20 | override def put(i: Int, v: scala.Any): Unit = throw new UnsupportedOperationException("This implementation of Record is immutable") 21 | 22 | override def get(key: String): Any = { 23 | val field = schema.getField(key) 24 | if (field == null) sys.error(s"Field $key does not exist in this record (schema=$schema, values=$values)") 25 | values(field.pos) 26 | } 27 | 28 | override def get(i: Int): Any = values(i) 29 | override def getSchema: Schema = schema 30 | } 31 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/RecordFormat.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.Schema 4 | import org.apache.avro.generic.IndexedRecord 5 | 6 | /** 7 | * Brings together [[ToRecord]] and [[FromRecord]] in a single interface. 8 | */ 9 | trait RecordFormat[T] extends ToRecord[T] with FromRecord[T] with Serializable 10 | 11 | /** 12 | * Returns a [[RecordFormat]] that will convert to/from 13 | * instances of T and avro Record's. 14 | */ 15 | object RecordFormat { 16 | 17 | def apply[T](schema: Schema)(using toRecord: ToRecord[T], fromRecord: FromRecord[T]): RecordFormat[T] = new RecordFormat[T] { 18 | override def from(record: IndexedRecord): T = fromRecord.from(record) 19 | override def to(t: T): Record = toRecord.to(t) 20 | } 21 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/ToRecord.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.Schema 4 | 5 | /** 6 | * Converts from instances of T into Record's. 7 | * 8 | * Note: This interface requires that T is marshalled 9 | * to an Avro GenericRecord / SpecificRecord, and therefore 10 | * is limited to use by case classes or traits. This interface 11 | * is essentially just a convenience wrapper around an 12 | * Encoder so you do not have to cast the result. 13 | * 14 | * If you wish to convert an avro type other than record use an Encoder directly. 15 | * 16 | */ 17 | trait ToRecord[T] extends Serializable { 18 | def to(t: T): Record 19 | } 20 | 21 | object ToRecord { 22 | def apply[T](schema: Schema)(using encoder: Encoder[T]): ToRecord[T] = new ToRecord[T] { 23 | def to(t: T): Record = encoder.encode(schema).apply(t) match { 24 | case record: Record => record 25 | case output => { 26 | val clazz = output.getClass 27 | throw new Avro4sEncodingException(s"Cannot marshall an instance of $t to a Record (had class $clazz, output was $output)") 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/avroutils/ByteBufferHelper.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.avroutils 2 | 3 | import java.nio.ByteBuffer 4 | 5 | private[avro4s] object ByteBufferHelper { 6 | def asArray(byteBuffer: ByteBuffer): Array[Byte] = { 7 | if (byteBuffer.hasArray) { 8 | byteBuffer.array() 9 | } else { 10 | val bytes = new Array[Byte](byteBuffer.remaining) 11 | byteBuffer.get(bytes) 12 | bytes 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/avroutils/EnumHelpers.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.avroutils 2 | 3 | import org.apache.avro.{Schema, SchemaBuilder} 4 | import collection.JavaConverters.asScalaBufferConverter 5 | 6 | object EnumHelpers { 7 | 8 | /** 9 | * Returns an enum schema which is a copy of this enum schema, adding the given default. 10 | */ 11 | def addDefault[E](default: E)(schema: Schema): Schema = 12 | require(schema.getType == Schema.Type.ENUM) 13 | SchemaBuilder 14 | .enumeration(schema.getName) 15 | .namespace(schema.getNamespace) 16 | .defaultSymbol(default.toString) 17 | .symbols(schema.getEnumSymbols.asScala.toList: _*) 18 | } 19 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/decoders/magnolia.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.decoders 2 | 3 | import com.sksamuel.avro4s.typeutils.{CaseClassShape, DatatypeShape, SealedTraitShape} 4 | import com.sksamuel.avro4s.{Decoder, Encoder} 5 | import magnolia1.{AutoDerivation, CaseClass, SealedTrait} 6 | 7 | trait MagnoliaDerivedDecoder extends AutoDerivation[Decoder] : 8 | 9 | override def join[T](ctx: CaseClass[Decoder, T]): Decoder[T] = 10 | DatatypeShape.of(ctx) match { 11 | case CaseClassShape.Record => new RecordDecoder(ctx) 12 | case CaseClassShape.ValueType => new RecordDecoder(ctx) 13 | } 14 | 15 | override def split[T](ctx: SealedTrait[Decoder, T]): Decoder[T] = 16 | DatatypeShape.of[T](ctx) match { 17 | case SealedTraitShape.TypeUnion => TypeUnions.decoder(ctx) 18 | case SealedTraitShape.Enum => SealedTraits.decoder(ctx) 19 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/decoders/options.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.decoders 2 | 3 | import com.sksamuel.avro4s.Decoder 4 | import com.sksamuel.avro4s.Encoder 5 | import org.apache.avro.Schema 6 | 7 | import scala.jdk.CollectionConverters.* 8 | 9 | class OptionDecoder[T](decoder: Decoder[T]) extends Decoder[Option[T]] { 10 | 11 | override def decode(schema: Schema): Any => Option[T] = { 12 | // nullables must be encoded with a union of 2 elements, one of which is null 13 | require(schema.getType == Schema.Type.UNION, { 14 | "Options can only be encoded with a UNION schema" 15 | }) 16 | require(schema.getTypes.size() >= 2, { 17 | "An option should be encoded with a UNION schema with at least 2 element types" 18 | }) 19 | val (isNull, isNotNull) = schema.getTypes().asScala.toList.partition(_.getType() == Schema.Type.NULL) 20 | require(isNull.size == 1, s"exactly one of the schemas must be null (found ${isNull.size})") 21 | val elementSchema = isNotNull match { 22 | case List(single) => single 23 | case more => Schema.createUnion(more.asJava) 24 | } 25 | 26 | val decode = decoder.decode(elementSchema) 27 | { value => if (value == null) None else Some(decode(value)) } 28 | } 29 | } 30 | 31 | trait OptionDecoders: 32 | given[T](using decoder: Decoder[T]): Decoder[Option[T]] = new OptionDecoder[T](decoder) 33 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/decoders/sealedtraits.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.decoders 2 | 3 | import com.sksamuel.avro4s.{ Decoder, Avro4sConfigurationException } 4 | import org.apache.avro.Schema 5 | import com.sksamuel.avro4s.avroutils.SchemaHelper 6 | import com.sksamuel.avro4s.typeutils.{Annotations, Names, EnumOrdering} 7 | import org.apache.avro.generic.GenericData 8 | import magnolia1.SealedTrait 9 | 10 | object SealedTraits { 11 | 12 | def decoder[T](ctx: magnolia1.SealedTrait[Decoder, T]): Decoder[T] = new Decoder[T] { 13 | override def decode(schema: Schema): Any => T = { 14 | require(schema.getType == Schema.Type.ENUM) 15 | val typeForSymbol: Map[GenericData.EnumSymbol, SealedTrait.Subtype[Decoder, T, _]] = 16 | ctx.subtypes.sortBy(_.index).sorted(EnumOrdering).zipWithIndex.map { (st, i) => 17 | val enumSymbol = GenericData.get.createEnum(schema.getEnumSymbols.get(i), schema).asInstanceOf[GenericData.EnumSymbol] 18 | enumSymbol -> st 19 | }.toMap 20 | 21 | { case value: GenericData.EnumSymbol => 22 | val symtype = typeForSymbol(value) 23 | val tc = symtype.typeclass 24 | tc.decode(value.getSchema)(value) 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/encoders/eithers.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.encoders 2 | 3 | import com.sksamuel.avro4s.Encoder 4 | import com.sksamuel.avro4s.avroutils.SchemaHelper 5 | import org.apache.avro.Schema 6 | 7 | trait EitherEncoders: 8 | given eitherEncoder[A, B] (using a: Encoder[A], b: Encoder[B]): Encoder[Either[A, B]] with 9 | override def encode(schema: Schema): Either[A, B] => AnyRef = { 10 | require(schema.isUnion) 11 | 12 | val leftSchema = SchemaHelper.extractEitherLeftSchema(schema) 13 | val rightSchema = SchemaHelper.extractEitherRightSchema(schema) 14 | 15 | val encodeA = a.encode(leftSchema) 16 | val encodeB = b.encode(rightSchema) 17 | 18 | { value => 19 | value match { 20 | case Left(l) => encodeA(l) 21 | case Right(r) => encodeB(r) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/encoders/magnolia.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.encoders 2 | 3 | import com.sksamuel.avro4s.typeutils.{CaseClassShape, DatatypeShape, SealedTraitShape} 4 | import com.sksamuel.avro4s.{Encoder, SchemaFor} 5 | import magnolia1.{CaseClass, AutoDerivation, SealedTrait, TypeInfo} 6 | import org.apache.avro.{Schema, SchemaBuilder} 7 | 8 | import scala.deriving.Mirror 9 | 10 | trait MagnoliaDerivedEncoder extends AutoDerivation[Encoder] : 11 | override def join[T](ctx: CaseClass[Encoder, T]): Encoder[T] = new RecordEncoder(ctx) 12 | 13 | override def split[T](ctx: SealedTrait[Encoder, T]): Encoder[T] = 14 | DatatypeShape.of[T](ctx) match { 15 | case SealedTraitShape.TypeUnion => TypeUnions.encoder(ctx) 16 | case SealedTraitShape.Enum => SealedTraits.encoder(ctx) 17 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/encoders/options.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.encoders 2 | 3 | import com.sksamuel.avro4s.Encoder 4 | import com.sksamuel.avro4s.FieldMapper 5 | import org.apache.avro.Schema 6 | 7 | import scala.jdk.CollectionConverters.* 8 | 9 | class OptionEncoder[T](encoder: Encoder[T]) extends Encoder[Option[T]] { 10 | 11 | override def encode(schema: Schema): Option[T] => AnyRef = { 12 | // nullables must be encoded with a union of 2 elements, one of which is null 13 | require(schema.getType == Schema.Type.UNION, { 14 | "Options can only be encoded with a UNION schema" 15 | }) 16 | require(schema.getTypes.size() >= 2, { 17 | "Options can only be encoded with a union schema with 2 or more types" 18 | }) 19 | val (isNull, isNotNull) = schema.getTypes().asScala.toList.partition(_.getType() == Schema.Type.NULL) 20 | require(isNull.size == 1, s"exactly one of the schemas must be null (found ${isNull.size})") 21 | 22 | val elementSchema = isNotNull match { 23 | case List(single) => single 24 | case more => Schema.createUnion(more.asJava) 25 | } 26 | val elementEncoder = encoder.encode(elementSchema) 27 | { option => option.fold(null)(elementEncoder) } 28 | } 29 | } 30 | 31 | trait OptionEncoders: 32 | given[T](using encoder: Encoder[T]): Encoder[Option[T]] = OptionEncoder[T](encoder) 33 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/encoders/primitives.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.encoders 2 | 3 | import com.sksamuel.avro4s.Encoder 4 | import org.apache.avro.Schema 5 | 6 | import java.nio.ByteBuffer 7 | 8 | trait PrimitiveEncoders { 9 | given LongEncoder: Encoder[Long] = Encoder(a => java.lang.Long.valueOf(a)) 10 | given Encoder[Int] = IntEncoder 11 | given ShortEncoder: Encoder[Short] = Encoder(a => java.lang.Short.valueOf(a)) 12 | given ByteEncoder: Encoder[Byte] = Encoder(a => java.lang.Byte.valueOf(a)) 13 | given DoubleEncoder: Encoder[Double] = Encoder(a => java.lang.Double.valueOf(a)) 14 | given FloatEncoder: Encoder[Float] = Encoder(a => java.lang.Float.valueOf(a)) 15 | given BooleanEncoder: Encoder[Boolean] = Encoder(a => java.lang.Boolean.valueOf(a)) 16 | } 17 | 18 | object IntEncoder extends Encoder[Int] { 19 | override def encode(schema: Schema): Int => AnyRef = { value => java.lang.Integer.valueOf(value) } 20 | } 21 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/encoders/sealedtraits.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.encoders 2 | 3 | import com.sksamuel.avro4s.typeutils.{Annotations, Names, EnumOrdering} 4 | import com.sksamuel.avro4s.{Encoder, SchemaFor} 5 | import magnolia1.SealedTrait 6 | import org.apache.avro.generic.GenericData 7 | import org.apache.avro.{Schema, SchemaBuilder} 8 | 9 | object SealedTraits { 10 | def encoder[T](ctx: SealedTrait[Encoder, T]): Encoder[T] = new Encoder[T] { 11 | override def encode(schema: Schema): T => AnyRef = { 12 | val symbolForSubtype: Map[SealedTrait.Subtype[Encoder, T, _], AnyRef] = ctx.subtypes.sortBy(_.index).sorted(EnumOrdering).zipWithIndex.map { 13 | case (st, i) => st -> GenericData.get.createEnum(schema.getEnumSymbols.get(i), schema) 14 | }.toMap 15 | { (value: T) => ctx.choose(value) { st => symbolForSubtype(st.subtype) } } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/encoders/unions.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.encoders 2 | 3 | import com.sksamuel.avro4s.avroutils.SchemaHelper 4 | import com.sksamuel.avro4s.typeutils.SubtypeOrdering 5 | import com.sksamuel.avro4s.typeutils.{Annotations, Names} 6 | import com.sksamuel.avro4s.{Encoder, SchemaFor} 7 | import magnolia1.SealedTrait 8 | import org.apache.avro.Schema 9 | 10 | object TypeUnions { 11 | 12 | /** 13 | * Builds an [[Encoder]] for a sealed trait enum. 14 | */ 15 | def encoder[T](ctx: SealedTrait[Encoder, T]): Encoder[T] = new Encoder[T] { 16 | override def encode(schema: Schema): T => AnyRef = { 17 | require(schema.isUnion) 18 | 19 | val encoderBySubtype = ctx.subtypes.sorted(SubtypeOrdering).map(st => { 20 | 21 | val annos: Annotations = new Annotations(st.annotations, st.inheritedAnnotations) 22 | val names = Names(st.typeInfo, annos) 23 | 24 | val subschema: Schema = SchemaHelper.extractTraitSubschema(names.fullName, schema) 25 | val encodeT: T => AnyRef = st.typeclass.asInstanceOf[Encoder[T]].encode(subschema) 26 | 27 | (st, encodeT) 28 | }).toMap 29 | 30 | { value => 31 | ctx.choose(value) { st => encoderBySubtype(st.subtype).apply(st.cast(value)) } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/exceptions.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | class Avro4sException(message: String) extends Exception(message: String) 4 | 5 | class Avro4sConfigurationException(message: String) extends Avro4sException(message) 6 | 7 | class Avro4sEncodingException(message: String) extends Avro4sException(message) 8 | 9 | class Avro4sDecodingException(message: String, val value: Any) extends Avro4sException(message) 10 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/format.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | enum AvroFormat: 4 | case Binary, Json, Data -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/bigdecimals.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | import org.apache.avro.{LogicalTypes, Schema, SchemaBuilder} 4 | 5 | case class ScalePrecision(scale: Int, precision: Int) 6 | 7 | object ScalePrecision { 8 | given default: ScalePrecision = ScalePrecision(2, 8) 9 | } 10 | 11 | trait BigDecimalSchemas: 12 | given(using sp: ScalePrecision): SchemaFor[BigDecimal] = new BigDecimalSchemaFor(sp) 13 | 14 | class BigDecimalSchemaFor(sp: ScalePrecision) extends SchemaFor[BigDecimal] : 15 | override def schema: Schema = LogicalTypes.decimal(sp.precision, sp.scale).addToSchema(SchemaBuilder.builder.bytesType) 16 | 17 | object BigDecimals { 18 | val AsString: SchemaFor[BigDecimal] = SchemaFor[BigDecimal](SchemaBuilder.builder.stringType) 19 | } 20 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/bytes.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import com.sksamuel.avro4s.SchemaFor 4 | import org.apache.avro.SchemaBuilder 5 | 6 | trait ByteIterableSchemas: 7 | given ByteArraySchemaFor: SchemaFor[Array[Byte]] = SchemaFor[Array[Byte]](SchemaBuilder.builder.bytesType) 8 | given ByteListSchemaFor: SchemaFor[List[Byte]] = ByteArraySchemaFor.forType 9 | given ByteSeqSchemaFor: SchemaFor[Seq[Byte]] = ByteArraySchemaFor.forType 10 | given ByteVectorSchemaFor: SchemaFor[Vector[Byte]] = ByteArraySchemaFor.forType -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/collections.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import com.sksamuel.avro4s.{DefaultFieldMapper, FieldMapper, SchemaFor} 4 | import org.apache.avro.{Schema, SchemaBuilder} 5 | 6 | trait CollectionSchemas: 7 | 8 | private def buildIterableSchemaFor[C[X] <: Iterable[X], T](using schemaFor: SchemaFor[T]): SchemaFor[C[T]] = 9 | schemaFor.map(SchemaBuilder.array.items(_)) 10 | 11 | given[T](using schemaFor: SchemaFor[T]): SchemaFor[Array[T]] = new SchemaFor[Array[T]] : 12 | override def schema: Schema = Schema.createArray(schemaFor.schema) 13 | 14 | given[T](using schemaFor: SchemaFor[T]): SchemaFor[Seq[T]] = buildIterableSchemaFor[Seq, T] 15 | 16 | given[T](using SchemaFor[T]): SchemaFor[Set[T]] = buildIterableSchemaFor[Set, T] 17 | 18 | given[T](using SchemaFor[T]): SchemaFor[Vector[T]] = buildIterableSchemaFor[Vector, T] 19 | 20 | given[T](using schemaFor: SchemaFor[T]): SchemaFor[List[T]] = buildIterableSchemaFor[List, T] 21 | 22 | given[V](using schemaFor: SchemaFor[V]): SchemaFor[Map[String, V]] = 23 | schemaFor.map(SchemaBuilder.map().values(_)) 24 | 25 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/eithers.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import com.sksamuel.avro4s.avroutils.SchemaHelper 4 | import com.sksamuel.avro4s.{FieldMapper, SchemaFor} 5 | import org.apache.avro.Schema 6 | 7 | trait EitherSchemas: 8 | given[A, B](using leftSchemaFor: SchemaFor[A], rightSchemaFor: SchemaFor[B]): SchemaFor[Either[A, B]] = 9 | new SchemaFor[Either[A, B]] : 10 | override def schema = SchemaFor(SchemaHelper.createSafeUnion(leftSchemaFor.schema, rightSchemaFor.schema)).schema -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/logicals.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import org.apache.avro.{LogicalType, Schema} 4 | 5 | object OffsetDateTimeLogicalType extends LogicalType("datetime-with-offset") { 6 | override def validate(schema: Schema): Unit = { 7 | super.validate(schema) 8 | if (schema.getType != Schema.Type.STRING) { 9 | throw new IllegalArgumentException("Logical type iso-datetime with offset must be backed by String") 10 | } 11 | } 12 | } 13 | 14 | object TimestampNanosLogicalType extends LogicalType("timestamp-nanos") { 15 | override def validate(schema: Schema): Unit = { 16 | super.validate(schema) 17 | if (schema.getType != Schema.Type.LONG) { 18 | throw new IllegalArgumentException("Logical type timestamp-nanos must be backed by long") 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/magnolia.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import com.sksamuel.avro4s.typeutils.{CaseClassShape, DatatypeShape, SealedTraitShape} 4 | import com.sksamuel.avro4s.{SchemaFor} 5 | import magnolia1.{CaseClass, AutoDerivation, SealedTrait, TypeInfo} 6 | import org.apache.avro.{Schema, SchemaBuilder} 7 | 8 | import scala.deriving.Mirror 9 | 10 | trait MagnoliaDerivedSchemas extends AutoDerivation[SchemaFor] : 11 | 12 | def join[T](ctx: CaseClass[SchemaFor, T]): SchemaFor[T] = 13 | DatatypeShape.of(ctx) match { 14 | case CaseClassShape.Record => Records.schema(ctx) 15 | case CaseClassShape.ValueType => ??? 16 | } 17 | 18 | override def split[T](ctx: SealedTrait[SchemaFor, T]): SchemaFor[T] = 19 | DatatypeShape.of[T](ctx) match { 20 | case SealedTraitShape.TypeUnion => TypeUnions.schema(ctx) 21 | case SealedTraitShape.Enum => SchemaFor[T](SealedTraits.schema(ctx)) 22 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/options.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import com.sksamuel.avro4s.avroutils.SchemaHelper 4 | import com.sksamuel.avro4s.{Avro4sException, FieldMapper, SchemaFor} 5 | import org.apache.avro.{Schema, SchemaBuilder} 6 | 7 | trait OptionSchemas { 8 | 9 | given SchemaFor[None.type] = NoneSchemaFor 10 | 11 | given[T](using schemaFor: SchemaFor[T]): SchemaFor[Option[T]] = new SchemaFor[Option[T]] { 12 | override def schema: Schema = { 13 | val rhs: Schema = schemaFor.schema 14 | if (rhs.isUnion) 15 | val types = rhs.getTypes 16 | types.add(0, Schema.create(Schema.Type.NULL)) 17 | Schema.createUnion(types) 18 | else 19 | Schema.createUnion(Schema.create(Schema.Type.NULL), rhs) 20 | } 21 | } 22 | } 23 | 24 | object NoneSchemaFor extends SchemaFor[None.type] : 25 | private val s = SchemaBuilder.builder.nullType 26 | override def schema: Schema = s -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/primitives.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import org.apache.avro.util.Utf8 4 | import org.apache.avro.{LogicalTypes, SchemaBuilder} 5 | import com.sksamuel.avro4s.SchemaFor 6 | import java.nio.ByteBuffer 7 | import java.util.UUID 8 | 9 | trait PrimitiveSchemas: 10 | given intSchemaFor: SchemaFor[Int] = SchemaFor[Int](SchemaBuilder.builder.intType) 11 | given SchemaFor[Byte] = intSchemaFor.forType 12 | given SchemaFor[Short] = intSchemaFor.forType 13 | given SchemaFor[Long] = SchemaFor[Long](SchemaBuilder.builder.longType) 14 | given SchemaFor[Float] = SchemaFor[Float](SchemaBuilder.builder.floatType) 15 | given SchemaFor[Double] = SchemaFor[Double](SchemaBuilder.builder.doubleType) 16 | given SchemaFor[scala.Boolean] = SchemaFor[Boolean](SchemaBuilder.builder.booleanType) 17 | given SchemaFor[ByteBuffer] = SchemaFor[ByteBuffer](SchemaBuilder.builder.bytesType) 18 | -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/scalaenums.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import com.sksamuel.avro4s.SchemaFor 4 | import org.apache.avro.{Schema, SchemaBuilder} 5 | 6 | import scala.quoted.Quotes 7 | import scala.quoted.Expr 8 | import scala.quoted.Type 9 | 10 | object ScalaEnums: 11 | inline def schema[T]: SchemaFor[T] = ${ schema } 12 | 13 | def schema[T:Type](using quotes: Quotes): Expr[SchemaFor[T]] = 14 | import quotes.reflect.* 15 | 16 | val tpe = TypeRepr.of[T] 17 | val t = tpe.typeSymbol.tree 18 | println(t) 19 | println(tpe.toString) 20 | '{ new SchemaFor[T] { 21 | println("hello") 22 | override def schema: Schema = SchemaBuilder.builder().intType() 23 | } } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/strings.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import org.apache.avro.util.Utf8 4 | import org.apache.avro.{LogicalTypes, Schema, SchemaBuilder} 5 | import com.sksamuel.avro4s.{SchemaFor} 6 | 7 | import java.nio.ByteBuffer 8 | import java.util.UUID 9 | 10 | trait StringSchemas: 11 | given StringSchemaFor: SchemaFor[String] = SchemaFor[String](SchemaBuilder.builder.stringType) 12 | given SchemaFor[Utf8] = StringSchemaFor.forType 13 | given SchemaFor[CharSequence] = StringSchemaFor.forType 14 | given SchemaFor[UUID] = SchemaFor[UUID](LogicalTypes.uuid().addToSchema(SchemaBuilder.builder.stringType)) 15 | 16 | def fixedStringSchemaFor(name: String, size: Int): SchemaFor[String] = SchemaFor(SchemaBuilder.fixed(name).size(size)) 17 | 18 | /** 19 | * Returns a [[Schema]] for strings that uses avro.java.string to specify that java strings should be used. 20 | */ 21 | object JavaStringSchemaFor extends SchemaFor[String] { 22 | val s = SchemaBuilder.builder.stringBuilder().prop("avro.java.string", "String").endString() 23 | override def schema: Schema = s 24 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/temporal.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import com.sksamuel.avro4s.SchemaFor 4 | import org.apache.avro.{LogicalTypes, SchemaBuilder} 5 | 6 | import java.sql.Timestamp 7 | import java.time.{Instant, LocalDate, LocalDateTime, LocalTime, OffsetDateTime} 8 | import java.util.Date 9 | 10 | trait TemporalSchemas: 11 | given InstantSchemaFor : SchemaFor[Instant] = SchemaFor[Instant](LogicalTypes.timestampMillis().addToSchema(SchemaBuilder.builder.longType)) 12 | given DateSchemaFor: SchemaFor[Date] = SchemaFor(LogicalTypes.date().addToSchema(SchemaBuilder.builder.intType)) 13 | given SchemaFor[java.sql.Date] = SchemaFor(LogicalTypes.date().addToSchema(SchemaBuilder.builder.intType)) 14 | given LocalDateSchemaFor: SchemaFor[LocalDate] = DateSchemaFor.forType 15 | given LocalDateTimeSchemaFor : SchemaFor[LocalDateTime] = SchemaFor(TimestampNanosLogicalType.addToSchema(SchemaBuilder.builder.longType)) 16 | given OffsetDateTimeSchemaFor : SchemaFor[OffsetDateTime] = SchemaFor(OffsetDateTimeLogicalType.addToSchema(SchemaBuilder.builder.stringType)) 17 | given LocalTimeSchemaFor : SchemaFor[LocalTime] = SchemaFor(LogicalTypes.timeMicros().addToSchema(SchemaBuilder.builder.longType)) 18 | given TimestampSchemaFor : SchemaFor[Timestamp] = SchemaFor[Timestamp](LogicalTypes.timestampMillis().addToSchema(SchemaBuilder.builder.longType)) -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/schemas/valuetypes.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schemas 2 | 3 | import com.sksamuel.avro4s.SchemaFor 4 | import com.sksamuel.avro4s.typeutils.{Annotations, Names} 5 | import magnolia1.CaseClass 6 | import org.apache.avro.SchemaBuilder 7 | import org.apache.avro.Schema 8 | 9 | object ValueTypes { 10 | 11 | /** 12 | * Builds a schema for a value type. 13 | */ 14 | def schema[T](ctx: CaseClass[SchemaFor, T]): Schema = 15 | val annos: Annotations = Annotations(ctx) // taking over @AvroFixed and the like 16 | val names = Names(ctx.typeInfo, annos) 17 | 18 | // if the class is a value type, then we need to use the schema for the single field inside the type 19 | // in other words, if we have `case class Foo(str: String) extends AnyVal` then this acts just like String. 20 | // if we have a value type AND @AvroFixed is present on the class, then we simply return a schema of type fixed 21 | annos.fixed match { 22 | case Some(size) => 23 | val builder = 24 | SchemaBuilder 25 | .fixed(names.name) 26 | .doc(annos.doc.orNull) 27 | .namespace(names.namespace) 28 | .aliases(annos.aliases: _*) 29 | annos.props.foreach { case (k, v) => builder.prop(k, v) } 30 | builder.size(size) 31 | case None => 32 | ctx.params.head.typeclass.schema 33 | } 34 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/typeutils/DatatypeShape.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.typeutils 2 | 3 | import com.sksamuel.avro4s.SchemaFor 4 | import magnolia1.{CaseClass, SealedTrait} 5 | 6 | enum CaseClassShape: 7 | case ValueType, Record 8 | 9 | enum SealedTraitShape: 10 | case TypeUnion, Enum 11 | 12 | object DatatypeShape: 13 | 14 | def of[T](ctx: SealedTrait[_, T]): SealedTraitShape = { 15 | val allSubtypesAreObjects = ctx.subtypes.forall(_.isObject) 16 | if (ctx.isEnum || allSubtypesAreObjects) SealedTraitShape.Enum else SealedTraitShape.TypeUnion 17 | } 18 | 19 | def of[Typeclass[_], T](ctx: CaseClass[Typeclass, T]): CaseClassShape = 20 | if (ctx.isValueClass) CaseClassShape.ValueType else CaseClassShape.Record -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/typeutils/EnumTypes.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.typeutils 2 | 3 | import magnolia1.SealedTrait 4 | 5 | object EnumOrdering extends Ordering[SealedTrait.Subtype[_, _, _]] { 6 | override def compare(a: SealedTrait.Subtype[_, _, _], b: SealedTrait.Subtype[_, _, _]): Int = { 7 | 8 | val annosA = new Annotations(a.annotations) 9 | val annosB = new Annotations(b.annotations) 10 | 11 | val priorityA = annosA.sortPriority.getOrElse(0F) 12 | val priorityB = annosB.sortPriority.getOrElse(0F) 13 | 14 | if (priorityA == priorityB) 0 else priorityB.compare(priorityA) 15 | } 16 | } -------------------------------------------------------------------------------- /avro4s-core/src/main/scala/com/sksamuel/avro4s/typeutils/Subtypes.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.typeutils 2 | 3 | import magnolia1.SealedTrait 4 | 5 | object SubtypeOrdering extends Ordering[SealedTrait.Subtype[_, _, _]] { 6 | override def compare(a: SealedTrait.Subtype[_, _, _], b: SealedTrait.Subtype[_, _, _]): Int = { 7 | 8 | val annosA = new Annotations(a.annotations) 9 | val annosB = new Annotations(b.annotations) 10 | 11 | val namesA = new Names(a.typeInfo, annosA) 12 | val namesB = new Names(b.typeInfo, annosB) 13 | 14 | val priorityA = annosA.sortPriority.getOrElse(999999F) 15 | val priorityB = annosB.sortPriority.getOrElse(999999F) 16 | 17 | if (priorityA == priorityB) namesA.fullName.compare(namesB.fullName) else priorityB.compare(priorityA) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/aliases_on_fields.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroAliasSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "str", 8 | "type": "string", 9 | "aliases": [ 10 | "cold" 11 | ] 12 | }, 13 | { 14 | "name": "long", 15 | "type": "long", 16 | "aliases": [ 17 | "bush", 18 | "kate" 19 | ] 20 | }, 21 | { 22 | "name": "int", 23 | "type": "int" 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/aliases_on_types.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroAliasSchemaTest", 5 | "aliases": [ 6 | "queen" 7 | ], 8 | "fields": [ 9 | { 10 | "name": "str", 11 | "type": "string" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/aliases_on_types_multiple.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroAliasSchemaTest", 5 | "aliases": [ 6 | "ledzep", 7 | "queen" 8 | ], 9 | "fields": [ 10 | { 11 | "name": "str", 12 | "type": "string" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/array.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "array", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "boolean" 12 | } 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/array_of_maps.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "array", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "map", 12 | "values": "string" 13 | } 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/arrayrecords.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "array", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "record", 12 | "name": "Nested", 13 | "fields": [ 14 | { 15 | "name": "goo", 16 | "type": "string" 17 | } 18 | ] 19 | } 20 | } 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_error.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "error", 3 | "name": "Flibble", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroErrorSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "a", 8 | "type": "string" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_error_field.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "VeryCross", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroErrorSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "flibble", 8 | "type": { 9 | "type": "error", 10 | "name": "Flibble", 11 | "fields": [ 12 | { 13 | "name": "a", 14 | "type": "string" 15 | } 16 | ] 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_name_class.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "wibble", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroNameSchemaTest", 5 | "fields": [ 6 | { 7 | "name" : "a", 8 | "type" : "string" 9 | }, 10 | { 11 | "name" : "b", 12 | "type" : "string" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_name_field.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Foo", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroNameSchemaTest", 5 | "fields": [ 6 | { 7 | "name" : "wibble", 8 | "type" : "string" 9 | }, 10 | { 11 | "name" : "wubble", 12 | "type" : "string" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_name_field_mapping.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Foo", 4 | "namespace": "com.sksamuel.avro4s.github.Github396", 5 | "fields": [ 6 | { 7 | "name" : "WIBBLE", 8 | "type" : "string" 9 | }, 10 | { 11 | "name" : "b_wubble", 12 | "type" : "string" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_name_java_enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "MyJavaEnum", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "symbols": [ 6 | "A", 7 | "B", 8 | "C" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_name_nested_java_enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Wibble", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroNameSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "e", 8 | "type": { 9 | "type": "enum", 10 | "name": "MyJavaEnum", 11 | "namespace": "com.sksamuel.avro4s.schema", 12 | "symbols": [ 13 | "A", 14 | "B", 15 | "C" 16 | ] 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_name_on_type_arg.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "DibDabDob", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "a", 8 | "type": { 9 | "type": "record", 10 | "name": "Generic__TypeArg", 11 | "fields": [ 12 | { 13 | "name": "value", 14 | "type": { 15 | "type": "record", 16 | "name": "TypeArg", 17 | "namespace": "com.sksamuel.avro4s.schema.First", 18 | "fields": [ 19 | { 20 | "name": "a", 21 | "type": "string" 22 | } 23 | ] 24 | } 25 | } 26 | ] 27 | } 28 | }, 29 | { 30 | "name": "b", 31 | "type": { 32 | "type": "record", 33 | "name": "Generic__supertypearg", 34 | "fields": [ 35 | { 36 | "name": "value", 37 | "type": { 38 | "type": "record", 39 | "name": "wibble", 40 | "namespace": "com.sksamuel.avro4s.schema.Second", 41 | "fields": [ 42 | { 43 | "name": "a", 44 | "type": "string" 45 | } 46 | ] 47 | } 48 | } 49 | ] 50 | } 51 | } 52 | ] 53 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_name_sealed_trait.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "foofoo", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "symbols": [ 6 | "Rainy", 7 | "Sunny" 8 | ] 9 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_name_sealed_trait_symbol.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "Benelux", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "symbols": [ 6 | "Netherlands", 7 | "Vlaanderen", 8 | "Luxembourg", 9 | "foofoo" 10 | ] 11 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_nodefault.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NoDefaultTest", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "a", 8 | "type": "string" 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_sort_priority_enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "Numeric", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "symbols": ["NaturalNumber", "RationalNumber", "RealNumber"] 6 | } 7 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_sort_priority_union.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "FightingStyleWrapper", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "fightingstyle", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "DefensiveFightingStyle", 12 | "fields": [ 13 | { 14 | "name": "has_armor", 15 | "type": "boolean" 16 | } 17 | ] 18 | }, 19 | { 20 | "type": "record", 21 | "name": "AggressiveFightingStyle", 22 | "fields": [ 23 | { 24 | "name": "agressiveness", 25 | "type": "float" 26 | } 27 | ] 28 | } 29 | ] 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_sort_priority_union_with_default.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "FightingStyleWrapperWithDefault", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "fightingstyle", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "AggressiveFightingStyle", 12 | "fields": [ 13 | { 14 | "name": "agressiveness", 15 | "type": "float" 16 | } 17 | ] 18 | }, 19 | { 20 | "type": "record", 21 | "name": "DefensiveFightingStyle", 22 | "fields": [ 23 | { 24 | "name": "has_armor", 25 | "type": "boolean" 26 | } 27 | ] 28 | } 29 | ], 30 | "default": { 31 | "agressiveness": 10.0 32 | } 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_union_position_enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "Numeric", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroUnionPositionSchemaTestContext", 5 | "symbols": ["NaturalNumber", "RationalNumber", "RealNumber"] 6 | } 7 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/avro_union_position_union.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "FightingStyleWrapper", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroUnionPositionSchemaTestContext", 5 | "fields": [ 6 | { 7 | "name": "fightingstyle", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "DefensiveFightingStyle", 12 | "fields": [ 13 | { 14 | "name": "has_armor", 15 | "type": "boolean" 16 | } 17 | ] 18 | }, 19 | { 20 | "type": "record", 21 | "name": "AggressiveFightingStyle", 22 | "fields": [ 23 | { 24 | "name": "agressiveness", 25 | "type": "float" 26 | } 27 | ] 28 | } 29 | ] 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal-scale-and-precision.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.BigDecimalSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "decimal", 8 | "type": { 9 | "type": "bytes", 10 | "logicalType": "decimal", 11 | "precision": 20, 12 | "scale": 8 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.BigDecimalSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "decimal", 8 | "type": { 9 | "type": "bytes", 10 | "logicalType": "decimal", 11 | "precision": 8, 12 | "scale": 2 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal_as_fixed.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "BigDecimalAsFixedTest", 4 | "namespace": "com.sksamuel.avro4s.schema.BigDecimalSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "decimal", 8 | "type": { 9 | "type": "fixed", 10 | "name": "bigdecimal", 11 | "namespace": "", 12 | "size": 55 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal_as_string.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "BigDecimalAsStringTest", 4 | "namespace": "com.sksamuel.avro4s.schema.BigDecimalSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "decimal", 8 | "type": "string" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal_bytes.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "BigDecimalTest", 4 | "namespace" : "com.sksamuel.avro4s", 5 | "fields" : [ { 6 | "name" : "decimal", 7 | "type" : { 8 | "type" : "bytes", 9 | "logicalType" : "decimal", 10 | "precision" : 8, 11 | "scale" : 2 12 | } 13 | } ] 14 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal_default.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "BigDecimalDefault", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "decimal", 8 | "default": "964.55", 9 | "type": { 10 | "type": "bytes", 11 | "logicalType": "decimal", 12 | "precision": 8, 13 | "scale": 2 14 | } 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal_nested_default.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "BigDecimalNestedDefault", 4 | "namespace": "com.sksamuel.avro4s", 5 | "fields": [ 6 | { 7 | "name": "decimal", 8 | "default" : "964.55", 9 | "type": { 10 | "type": "bytes", 11 | "logicalType": "decimal", 12 | "precision": 8, 13 | "scale": 2 14 | } 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal_option.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "BigDecimalOption", 4 | "namespace": "com.sksamuel.avro4s.schema.BigDecimalSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "decimal", 8 | "type": [ 9 | "null", 10 | { 11 | "type": "bytes", 12 | "logicalType": "decimal", 13 | "precision": 8, 14 | "scale": 2 15 | } 16 | ] 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal_seq.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "BigDecimalSeq", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "biggies", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "bytes", 12 | "logicalType": "decimal", 13 | "precision": 8, 14 | "scale": 2 15 | } 16 | } 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bigdecimal_seq_option.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "BigDecimalSeqOption", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "biggies", 8 | "type": { 9 | "type": "array", 10 | "items": [ 11 | "null", 12 | { 13 | "type": "bytes", 14 | "logicalType": "decimal", 15 | "precision": 8, 16 | "scale": 2 17 | } 18 | ] 19 | } 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/boolean.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.BasicSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "booly", 8 | "type": "boolean" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/byte_array.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ByteArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "z", 8 | "type": "bytes" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bytebuffer.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ByteArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "z", 8 | "type": "bytes" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/bytes.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.BasicSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "bytes", 8 | "type": "bytes" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/case_class_default_values.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Cuppers", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "cupcat", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "Snoutley", 12 | "fields": [ 13 | { 14 | "name": "snoutley", 15 | "type": "string" 16 | } 17 | ] 18 | }, 19 | { 20 | "type": "record", 21 | "name": "Rendal", 22 | "fields": [] 23 | } 24 | ], 25 | "default": { 26 | "snoutley" : "hates varg" 27 | } 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/case_object_default_values.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NoVarg", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "cupcat", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "Rendal", 12 | "fields": [] 13 | }, 14 | { 15 | "type": "record", 16 | "name": "Snoutley", 17 | "fields": [ 18 | { 19 | "name": "snoutley", 20 | "type": "string" 21 | } 22 | ] 23 | } 24 | ], 25 | "default": {} 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/class_of_list_of_maps.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "ship", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "map", 12 | "values": "string" 13 | } 14 | } 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/class_with_list_of_maps.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "ship", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "map", 12 | "values": "string" 13 | } 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/coproduct.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "CPWrapper", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "u", 8 | "type": [ 9 | "int", 10 | "string", 11 | "boolean", 12 | { 13 | "type": "record", 14 | "name": "Gimble", 15 | "fields": [ 16 | { 17 | "name": "x", 18 | "type": "string" 19 | } 20 | ] 21 | } 22 | ] 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/coproduct_of_coproducts.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "CoproductOfCoproducts", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "cp", 8 | "type": [ 9 | "int", 10 | "string", 11 | "boolean" 12 | ] 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/coproduct_option.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "CPWithOption", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "u", 8 | "type": [ 9 | "null", 10 | "int", 11 | "string", 12 | "boolean", 13 | { 14 | "type": "record", 15 | "name": "Gimble", 16 | "fields": [ 17 | { 18 | "name": "x", 19 | "type": "string" 20 | } 21 | ] 22 | } 23 | ] 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/coproduct_with_default.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "CPWithDefault", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "u", 8 | "type": [ 9 | "int", 10 | "string", 11 | "boolean", 12 | { 13 | "type": "record", 14 | "name": "Gimble", 15 | "fields": [ 16 | { 17 | "name": "x", 18 | "type": "string" 19 | } 20 | ] 21 | } 22 | ], 23 | "default": 123 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/date.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "DateTest", 4 | "namespace": "com.sksamuel.avro4s.schema.DateSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "date", 8 | "type": { 9 | "type": "int", 10 | "logicalType": "date" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/deeply_nested_generic_with_value_type.json: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "Generic__Option__Seq__Thing1Id", 4 | "namespace" : "com.sksamuel.avro4s.schema.GenericSchemaTest", 5 | "fields" : [ { 6 | "name" : "t", 7 | "type" : [ "null", { 8 | "type" : "array", 9 | "items" : "int" 10 | } ] 11 | } ] 12 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/deeply_nested_generics.json: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "Outer__Thing1Id_Option__Seq__Thing2", 4 | "namespace" : "com.sksamuel.avro4s.schema", 5 | "fields" : [ { 6 | "name" : "id", 7 | "type" : { 8 | "type" : "string", 9 | "logicalType" : "uuid" 10 | } 11 | }, { 12 | "name" : "innerThing", 13 | "type" : { 14 | "type" : "record", 15 | "name" : "Inner__Thing1Id_Option__Seq__Thing2", 16 | "fields" : [ { 17 | "name" : "id", 18 | "type" : "string" 19 | }, { 20 | "name" : "left", 21 | "type" : "int" 22 | }, { 23 | "name" : "right", 24 | "type" : [ "null", { 25 | "type" : "array", 26 | "items" : { 27 | "type" : "record", 28 | "name" : "Thing2", 29 | "fields" : [ { 30 | "name" : "id", 31 | "type" : { 32 | "type" : "string", 33 | "logicalType" : "uuid" 34 | } 35 | }, { 36 | "name" : "name", 37 | "type" : "string" 38 | } ] 39 | } 40 | } ], 41 | "default" : null 42 | } ] 43 | } 44 | } ] 45 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/deepnested.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Level1", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "level2", 8 | "type": { 9 | "type": "record", 10 | "name": "Level2", 11 | "fields": [ 12 | { 13 | "name": "level3", 14 | "type": { 15 | "type": "record", 16 | "name": "Level3", 17 | "fields": [ 18 | { 19 | "name": "level4", 20 | "type": { 21 | "type": "record", 22 | "name": "Level4", 23 | "fields": [ 24 | { 25 | "name": "str", 26 | "type": { 27 | "type": "map", 28 | "values": "string" 29 | } 30 | } 31 | ] 32 | } 33 | } 34 | ] 35 | } 36 | } 37 | ] 38 | } 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/default_values_boolean.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "ClassWithDefaultBoolean", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "b", 8 | "type": "boolean", 9 | "default" : true 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/default_values_double.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "ClassWithDefaultDouble", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "d", 8 | "type": "double", 9 | "default" : 123.456 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/default_values_float.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "ClassWithDefaultFloat", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "f", 8 | "type": "float", 9 | "default" : 123.458 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/default_values_instant.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "ClassWithDefaultInstant", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "min", 8 | "type": { 9 | "type": "long", 10 | "logicalType": "timestamp-millis" 11 | }, 12 | "default": -9223372036854775808 13 | }, 14 | { 15 | "name": "max", 16 | "type": { 17 | "type": "long", 18 | "logicalType": "timestamp-millis" 19 | }, 20 | "default": 9223372036854775807 21 | }, 22 | { 23 | "name": "epoch", 24 | "type": { 25 | "type": "long", 26 | "logicalType": "timestamp-millis" 27 | }, 28 | "default": 0 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/default_values_int.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "ClassWithDefaultInt", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "i", 8 | "type": "int", 9 | "default" : 123 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/default_values_long.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "ClassWithDefaultLong", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "l", 8 | "type": "long", 9 | "default" : 1468920998000 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/default_values_optional_union.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "DogProspect", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "dog", 8 | "type": [ 9 | "null", 10 | { 11 | "type": "record", 12 | "name": "UnderDog", 13 | "fields": [ 14 | { 15 | "name": "how_unfortunate", 16 | "type": "double" 17 | } 18 | ] 19 | }, 20 | { 21 | "type": "record", 22 | "name": "UpperDog", 23 | "fields": [ 24 | { 25 | "name": "how_fortunate", 26 | "type": "double" 27 | } 28 | ] 29 | } 30 | ], 31 | "default": null 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/default_values_string.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "ClassWithDefaultString", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "s", 8 | "type": "string", 9 | "default" : "foo" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/doc_annotation_class.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroDocSchemaTest", 5 | "doc" : "hello; is it me youre looking for", 6 | "fields": [ 7 | { 8 | "name": "str", 9 | "type": "string" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/doc_annotation_field.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroDocSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "str", 8 | "type": "string", 9 | "doc" : "hello its me" 10 | }, 11 | { 12 | "name": "long", 13 | "type": "long", 14 | "doc" : "I am a long" 15 | }, 16 | { 17 | "name": "int", 18 | "type": "int" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/doc_annotation_field_struct.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroDocSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "nested", 8 | "doc": "c", 9 | "type": { 10 | "type": "record", 11 | "name": "Nested", 12 | "fields": [ 13 | { 14 | "name": "foo", 15 | "type": "string", 16 | "doc": "b" 17 | } 18 | ] 19 | } 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/doc_annotation_value_type.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated123", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "a", 8 | "type": "string", 9 | "doc": "wibble" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/doc_field_regular_case_class.json: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "Message", 4 | "namespace" : "com.sksamuel.avro4s.schema", 5 | "fields" : [ { 6 | "name" : "record1", 7 | "type" : { 8 | "type" : "record", 9 | "name" : "Record1", 10 | "doc" : "This is a record", 11 | "fields" : [ { 12 | "name" : "field", 13 | "type" : "string" 14 | } ] 15 | } 16 | } ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/double.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.BasicSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "double", 8 | "type": "double" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/either.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.EitherSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "either", 8 | "type": [ 9 | "string", 10 | "double" 11 | ] 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/either_record.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.EitherSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "either", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "Goo", 12 | "fields": [ 13 | { 14 | "name": "s", 15 | "type": "string" 16 | } 17 | ] 18 | }, 19 | { 20 | "type": "record", 21 | "name": "Foo", 22 | "fields": [ 23 | { 24 | "name": "b", 25 | "type": "boolean" 26 | } 27 | ] 28 | } 29 | ] 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/either_record_with_avro_namespace.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.EitherSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "either", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "Goo", 12 | "namespace": "mm", 13 | "fields": [ 14 | { 15 | "name": "s", 16 | "type": "string" 17 | } 18 | ] 19 | }, 20 | { 21 | "type": "record", 22 | "name": "Foo", 23 | "namespace": "nn", 24 | "fields": [ 25 | { 26 | "name": "b", 27 | "type": "boolean" 28 | } 29 | ] 30 | } 31 | ] 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/eithers.avro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sksamuel/avro4s/e9c5772edf639b3178ed0fd352b89a17a4c5d835/avro4s-core/src/test/resources/eithers.avro -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/field_mapper_default.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NamingStrategyTest", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "camelCase", 8 | "type": "string" 9 | }, 10 | { 11 | "name": "lower", 12 | "type": "string" 13 | }, 14 | { 15 | "name": "multipleWordsInThis", 16 | "type": "string" 17 | }, 18 | { 19 | "name": "StartsWithUpper", 20 | "type": "string" 21 | }, 22 | { 23 | "name": "nested", 24 | "type": { 25 | "type": "record", 26 | "name": "NamingStrategy2", 27 | "fields": [ 28 | { 29 | "name": "camelCase", 30 | "type": "string" 31 | } 32 | ] 33 | } 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/field_mapper_pascal.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NamingStrategyTest", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "CamelCase", 8 | "type": "string" 9 | }, 10 | { 11 | "name": "Lower", 12 | "type": "string" 13 | }, 14 | { 15 | "name": "MultipleWordsInThis", 16 | "type": "string" 17 | }, 18 | { 19 | "name": "StartsWithUpper", 20 | "type": "string" 21 | }, 22 | { 23 | "name": "Nested", 24 | "type": { 25 | "type": "record", 26 | "name": "NamingStrategy2", 27 | "fields": [ 28 | { 29 | "name": "CamelCase", 30 | "type": "string" 31 | } 32 | ] 33 | } 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/field_mapper_snake.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NamingStrategyTest", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "camel_case", 8 | "type": "string" 9 | }, 10 | { 11 | "name": "lower", 12 | "type": "string" 13 | }, 14 | { 15 | "name": "multiple_words_in_this", 16 | "type": "string" 17 | }, 18 | { 19 | "name": "starts_with_upper", 20 | "type": "string" 21 | }, 22 | { 23 | "name": "nested", 24 | "type": { 25 | "type": "record", 26 | "name": "NamingStrategy2", 27 | "fields": [ 28 | { 29 | "name": "camel_case", 30 | "type": "string" 31 | } 32 | ] 33 | } 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/fixed_string.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "FixedStringField", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "mystring", 8 | "type": { 9 | "type": "fixed", 10 | "name": "mystring", 11 | "size": 7 12 | } 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/fixed_string_top_level_value_type.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "fixed", 3 | "name": "FixedValueClass", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "size": 8 6 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/fixed_string_value_type_as_field.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "FooWithValue", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "z", 8 | "type": { 9 | "type": "fixed", 10 | "name": "FixedValueClass", 11 | "size": 8 12 | } 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/float.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.BasicSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "float", 8 | "type": "float" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/generic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "SameGenericWithDifferentTypeArgs", 4 | "namespace": "com.sksamuel.avro4s.schema.GenericSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "gi", 8 | "type": { 9 | "type": "record", 10 | "name": "Generic__Int", 11 | "fields": [ 12 | { 13 | "name": "t", 14 | "type": "int" 15 | } 16 | ] 17 | } 18 | }, 19 | { 20 | "name": "gs", 21 | "type": { 22 | "type": "record", 23 | "name": "Generic__String", 24 | "fields": [ 25 | { 26 | "name": "t", 27 | "type": "string" 28 | } 29 | ] 30 | } 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/genericSchema.avsc: -------------------------------------------------------------------------------- 1 | {"type":"record","name":"MyData","namespace":"com.sksamuel.avro4s","fields":[{"name":"i","type":{"type":"record","name":"MyWrapper_Int","fields":[{"name":"a","type":"int"}]}},{"name":"s","type":["null",{"type":"record","name":"MyWrapper_String","fields":[{"name":"a","type":"string"}]}]}]} 2 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/generic_disabled.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "GenericDisabled", 4 | "namespace": "com.sksamuel.avro4s.schema.GenericSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "t", 8 | "type": "string" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/generic_int.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Generic__Int", 4 | "namespace": "com.sksamuel.avro4s.schema.GenericSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "t", 8 | "type": "int" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/generic_string.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Generic__String", 4 | "namespace": "com.sksamuel.avro4s.schema.GenericSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "t", 8 | "type": "string" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github/github_318.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "CoproductWithAdt", 4 | "namespace": "com.sksamuel.avro4s.github", 5 | "fields": [ 6 | { 7 | "name": "cp", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "Bar", 12 | "namespace": "com.sksamuel.avro4s.github.MyAdt", 13 | "fields": [ 14 | { 15 | "name": "id", 16 | "type": "int" 17 | } 18 | ] 19 | }, 20 | { 21 | "type": "record", 22 | "name": "Foo", 23 | "namespace": "com.sksamuel.avro4s.github.MyAdt", 24 | "fields": [ 25 | { 26 | "name": "name", 27 | "type": "string" 28 | } 29 | ] 30 | }, 31 | "boolean" 32 | ] 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github/github_330.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Foo330", 4 | "namespace": "com.sksamuel.avro4s.github", 5 | "fields": [ 6 | { 7 | "name": "values", 8 | "type": { 9 | "type": "array", 10 | "items": [ 11 | { 12 | "type": "record", 13 | "name": "ForeignKeySetting", 14 | "fields": [ 15 | { 16 | "name": "targetEntityCode", 17 | "type": "string" 18 | }, 19 | { 20 | "name": "targetFieldName", 21 | "type": "string" 22 | } 23 | ] 24 | }, 25 | { 26 | "type": "record", 27 | "name": "PrimaryKeySetting", 28 | "fields": [ 29 | { 30 | "name": "attributes", 31 | "type": { 32 | "type": "map", 33 | "values": "int" 34 | } 35 | } 36 | ] 37 | } 38 | ] 39 | } 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github/github_331.json: -------------------------------------------------------------------------------- 1 | "string" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github/github_346.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "MyRenamedEnum", 4 | "namespace": "com.foo", 5 | "symbols": [ 6 | "Bussel", 7 | "Hussel" 8 | ] 9 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github/github_389.json: -------------------------------------------------------------------------------- 1 | {"type":"string","logicalType":"datetime-with-offset"} -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github254_a.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "A", 4 | "namespace": "com.sksamuel.avro4s.github.Github254", 5 | "fields": [ 6 | { 7 | "name": "c", 8 | "type": { 9 | "type": "enum", 10 | "name": "C", 11 | "symbols": [ 12 | "c1", 13 | "c2" 14 | ] 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github254_b.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "B", 4 | "namespace": "com.sksamuel.avro4s.github.Github254", 5 | "fields": [ 6 | { 7 | "name": "as", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "record", 12 | "name": "A", 13 | "fields": [ 14 | { 15 | "name": "c", 16 | "type": { 17 | "type": "enum", 18 | "name": "C", 19 | "symbols": [ 20 | "c1", 21 | "c2" 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | } 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github254_lista.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": { 4 | "type": "record", 5 | "name": "A", 6 | "namespace": "com.sksamuel.avro4s.github.Github254", 7 | "fields": [ 8 | { 9 | "name": "c", 10 | "type": 11 | { 12 | "type": "enum", 13 | "name": "C", 14 | "symbols": [ 15 | "c1", 16 | "c2" 17 | ] 18 | } 19 | } 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github292.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "record", 4 | "name": "Bar", 5 | "namespace": "com.sksamuel.avro4s.github", 6 | "fields": [ 7 | { 8 | "name": "value", 9 | "type": "int" 10 | } 11 | ] 12 | }, 13 | { 14 | "type": "record", 15 | "name": "Foo", 16 | "namespace": "com.sksamuel.avro4s.github", 17 | "fields": [ 18 | { 19 | "name": "value", 20 | "type": "string" 21 | }, 22 | { 23 | "name": "payload", 24 | "type": { 25 | "type": "record", 26 | "name": "Payload__String", 27 | "fields": [ 28 | { 29 | "name": "value", 30 | "type": "string" 31 | } 32 | ] 33 | } 34 | } 35 | ] 36 | }, 37 | { 38 | "type": "record", 39 | "name": "Invert", 40 | "namespace": "com.sksamuel.avro4s.github", 41 | "fields": [ 42 | { 43 | "name": "i", 44 | "type": { 45 | "type": "record", 46 | "name": "InvertibleComplexWrapper", 47 | "fields": [ 48 | { 49 | "name": "unwrap", 50 | "type": [ 51 | "Bar", 52 | "Foo" 53 | ] 54 | } 55 | ] 56 | } 57 | } 58 | ] 59 | } 60 | ] -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github295.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "record", 4 | "name": "OuterConcrete295", 5 | "namespace": "com.sksamuel.avro4s.github", 6 | "fields": [ 7 | { 8 | "name": "inner", 9 | "type": [ 10 | { 11 | "type": "record", 12 | "name": "InnerTraitConcrete295", 13 | "fields": [ 14 | { 15 | "name": "v", 16 | "type": "int" 17 | } 18 | ] 19 | }, 20 | { 21 | "type": "record", 22 | "name": "InnerTraitConcrete295_2", 23 | "fields": [ 24 | { 25 | "name": "v", 26 | "type": "int" 27 | } 28 | ] 29 | } 30 | ] 31 | } 32 | ] 33 | } 34 | ] -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/github69.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Message__MyRecord", 4 | "namespace": "com.sksamuel.avro4s.github", 5 | "fields": [ 6 | { 7 | "name": "payload", 8 | "type": { 9 | "type": "record", 10 | "name": "MyRecord", 11 | "fields": [ 12 | { 13 | "name": "key", 14 | "type": "string" 15 | }, 16 | { 17 | "name": "str1", 18 | "type": "string" 19 | }, 20 | { 21 | "name": "str2", 22 | "type": "string" 23 | }, 24 | { 25 | "name": "int1", 26 | "type": "int" 27 | } 28 | ] 29 | } 30 | }, 31 | { 32 | "name": "identity", 33 | "type": "string", 34 | "default": "5b16ca84-f9e1-46a9-bc5c-8c0052b6dd16" 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/instant.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "InstantTest", 4 | "namespace": "com.sksamuel.avro4s.schema.DateSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "instant", 8 | "type": { 9 | "type": "long", 10 | "logicalType": "timestamp-millis" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/integer.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.BasicSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "inty", 8 | "type": "int" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/java_enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "JavaEnum", 4 | "namespace": "com.sksamuel.avro4s.schema.EnumSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "wine", 8 | "type": { 9 | "type": "enum", 10 | "name": "Wine", 11 | "namespace": "com.sksamuel.avro4s.schema", 12 | "symbols": [ 13 | "Malbec", 14 | "Shiraz", 15 | "CabSav", 16 | "Merlot" 17 | ] 18 | } 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/java_enum_option.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "OptionalJavaEnum", 4 | "namespace": "com.sksamuel.avro4s.schema.EnumSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "wine", 8 | "type": [ 9 | "null", 10 | { 11 | "type": "enum", 12 | "name": "Wine", 13 | "namespace": "com.sksamuel.avro4s.schema", 14 | "symbols": [ 15 | "Malbec", 16 | "Shiraz", 17 | "CabSav", 18 | "Merlot" 19 | ] 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/java_enum_top_level.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "Wine", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "symbols": [ 6 | "Malbec", 7 | "Shiraz", 8 | "CabSav", 9 | "Merlot" 10 | ] 11 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/java_enum_top_level_with_default.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "Wine", 4 | "namespace": "test", 5 | "symbols": [ 6 | "Malbec", 7 | "Shiraz", 8 | "CabSav", 9 | "Merlot" 10 | ], 11 | "default": "CabSav", 12 | "hello": "world" 13 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/java_string.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Foo", 4 | "namespace": "com.sksamuel.avro4s.schema.StringSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "s", 8 | "type": { 9 | "type": "string", 10 | "avro.java.string": "String" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/list.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NestedListString", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "list", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "string" 12 | } 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/list_of_maps.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "list", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "map", 12 | "values": "string" 13 | } 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/listrecords.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "list", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "record", 12 | "name": "Nested", 13 | "fields": [ 14 | { 15 | "name": "goo", 16 | "type": "string" 17 | } 18 | ] 19 | } 20 | } 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/local_class_namespace.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NamespaceTestFoo", 4 | "namespace": "com.sksamuel.avro4s.schema.NamespaceSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "inner", 8 | "type": "string" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/localdate.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "LocalDateTest", 4 | "namespace": "com.sksamuel.avro4s.schema.DateSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "date", 8 | "type": { 9 | "type": "int", 10 | "logicalType": "date" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/localdatetime.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "LocalDateTimeTest", 4 | "namespace": "com.sksamuel.avro4s.schema.DateSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "time", 8 | "type": { 9 | "type": "long", 10 | "logicalType": "timestamp-nanos" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/localtime.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "LocalTimeTest", 4 | "namespace": "com.sksamuel.avro4s.schema.DateSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "time", 8 | "type": { 9 | "type": "long", 10 | "logicalType": "time-micros" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/long.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.BasicSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "foo", 8 | "type": "long" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/map_int.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.MapSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "map", 8 | "type": { 9 | "type": "map", 10 | "values": "int" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/map_option.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.MapSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "map", 8 | "type": { 9 | "type": "map", 10 | "values": [ 11 | "null", 12 | "boolean" 13 | ] 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/map_record.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.MapSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "map", 8 | "type": { 9 | "type": "map", 10 | "values": { 11 | "type": "record", 12 | "name": "Nested", 13 | "fields": [ 14 | { 15 | "name": "goo", 16 | "type": "string" 17 | } 18 | ] 19 | } 20 | } 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/map_seq_nested.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.MapSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "map", 8 | "type": { 9 | "type": "map", 10 | "values": { 11 | "type": "array", 12 | "items": { 13 | "type": "record", 14 | "name": "Nested", 15 | "fields": [ 16 | { 17 | "name": "goo", 18 | "type": "string" 19 | } 20 | ] 21 | } 22 | } 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/map_seq_string.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.MapSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "map", 8 | "type": { 9 | "type": "map", 10 | "values": { 11 | "type": "array", 12 | "items": "string" 13 | } 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/map_string.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.MapSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "map", 8 | "type": { 9 | "type": "map", 10 | "values": "string" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/namespace.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "AnnotatedNamespace", 4 | "namespace" : "com.yuval", 5 | "fields" : [ { 6 | "name" : "s", 7 | "type" : "string" 8 | }, { 9 | "name" : "internal", 10 | "type" : { 11 | "type" : "record", 12 | "name" : "InternalAnnotated", 13 | "namespace" : "com.yuval.internal", 14 | "fields" : [ { 15 | "name" : "i", 16 | "type" : "int" 17 | } ] 18 | } 19 | } ] 20 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/namespace_class_adt_field.avsc: -------------------------------------------------------------------------------- 1 | [ { 2 | "type" : "record", 3 | "name" : "TestAnnotatedImpl", 4 | "namespace" : "com.yuval", 5 | "fields" : [ { 6 | "name" : "value", 7 | "type" : { 8 | "type" : "record", 9 | "name" : "AnnotatedNested", 10 | "namespace" : "com.yuval.nested", 11 | "fields" : [ ] 12 | } 13 | } ] 14 | } ] 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/namespace_empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Foo", 4 | "fields": [ 5 | { 6 | "name": "s", 7 | "type": "string" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/namespace_enum_class_level.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Location", 4 | "namespace": "wibble", 5 | "fields": [ 6 | { 7 | "name": "city", 8 | "type": { 9 | "type": "record", 10 | "name": "City", 11 | "namespace": "wobble", 12 | "fields": [ 13 | { 14 | "name": "name", 15 | "type": "string" 16 | } 17 | ] 18 | } 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/namespace_enum_field_level.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Teapot", 4 | "namespace": "wibble", 5 | "fields": [ 6 | { 7 | "name": "tea", 8 | "type": { 9 | "type": "record", 10 | "name": "Tea", 11 | "namespace": "wobble", 12 | "fields": [ 13 | { 14 | "name": "name", 15 | "type": "string" 16 | } 17 | ] 18 | } 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/namespace_enum_trait_level.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "Africa", 4 | "namespace": "wobble", 5 | "symbols": [ 6 | "Cameroon", 7 | "Chad", 8 | "Comoros" 9 | ] 10 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/naming_strategy_lisp.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NamingStrategyTest", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "camelCase", 8 | "type": "string" 9 | }, 10 | { 11 | "name": "lower", 12 | "type": "string" 13 | }, 14 | { 15 | "name": "multipleWordsInThis", 16 | "type": "string" 17 | }, 18 | { 19 | "name": "starts-with-upper", 20 | "type": "string" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/nested.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NestedTest", 4 | "namespace": "com.sksamuel.avro4s.schema.BasicSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "foo", 8 | "type": "string" 9 | }, 10 | { 11 | "name": "nested", 12 | "type": { 13 | "type": "record", 14 | "name": "Nested", 15 | "fields": [ 16 | { 17 | "name": "goo", 18 | "type": "string" 19 | } 20 | ] 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/nested_adts.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Napper", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "nibble", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "Nabble", 12 | "fields": [ 13 | { 14 | "name": "str", 15 | "type": "string" 16 | }, 17 | { 18 | "name": "age", 19 | "type": "int" 20 | } 21 | ] 22 | }, 23 | { 24 | "type": "record", 25 | "name": "Nobble", 26 | "fields": [ 27 | { 28 | "name": "str", 29 | "type": "string" 30 | }, 31 | { 32 | "name": "place", 33 | "type": "string" 34 | } 35 | ] 36 | } 37 | ] 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/nested_in_uppercase_pkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "ClassInUppercasePackage", 4 | "namespace": "com.sksamuel.avro4s.examples.UppercasePkg", 5 | "fields": [ 6 | { 7 | "name": "s", 8 | "type": "string" 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/nested_multiple.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Outer", 4 | "namespace": "com.sksamuel.avro4s.schema.BasicSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "middle", 8 | "type": { 9 | "type": "record", 10 | "name": "Middle", 11 | "fields": [ 12 | { 13 | "name": "inner", 14 | "type": { 15 | "type": "record", 16 | "name": "Inner", 17 | "fields": [ 18 | { 19 | "name": "goo", 20 | "type": "string" 21 | } 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/none.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.OptionSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "option", 8 | "type": "null" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/object_namespaces.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Outer", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "inner", 8 | "type": { 9 | "type": "record", 10 | "name": "Inner", 11 | "namespace": "com.sksamuel.avro4s.schema.Outer", 12 | "fields": [ 13 | { 14 | "name": "s", 15 | "type": "string" 16 | } 17 | ] 18 | } 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/object_namespaces_local.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "A", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "inner", 8 | "type": { 9 | "type": "record", 10 | "name": "B", 11 | "namespace": "com.sksamuel.avro4s.schema.ObjectNamespaceTest.A", 12 | "fields": [ 13 | { 14 | "name": "s", 15 | "type": "string" 16 | } 17 | ] 18 | } 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/option.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.OptionSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "option", 8 | "type": [ 9 | "null", 10 | "string" 11 | ] 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/option_default_value.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "OptionWithDefault", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "name", 8 | "type": [ 9 | "string", 10 | "null" 11 | ], 12 | "default": "f" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/option_either.json: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "Test", 4 | "namespace" : "com.sksamuel.avro4s.schema.OptionSchemaTest", 5 | "fields" : [ { 6 | "name" : "option", 7 | "type" : [ "null", "string", "boolean" ] 8 | } ] 9 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/option_enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "Test", 4 | "namespace" : "com.sksamuel.avro4s.schema.OptionSchemaTest", 5 | "fields" : [ { 6 | "name" : "option", 7 | "type" : [ "null", { 8 | "type" : "enum", 9 | "name" : "T", 10 | "symbols" : [ "A", "B", "C" ] 11 | } ] 12 | } ] 13 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/option_from_null_default.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "FieldWithNull", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "name", 8 | "type": [ 9 | "null", 10 | "string" 11 | ], 12 | "default": null 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/option_sealed_trait.json: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "Test", 4 | "namespace" : "com.sksamuel.avro4s.schema.OptionSchemaTest", 5 | "fields" : [ { 6 | "name" : "option", 7 | "type" : [ "null", { 8 | "type" : "record", 9 | "name" : "A", 10 | "fields" : [ { 11 | "name" : "a", 12 | "type" : "string" 13 | } ] 14 | }, { 15 | "type" : "record", 16 | "name" : "B", 17 | "fields" : [ { 18 | "name" : "b", 19 | "type" : "string" 20 | } ] 21 | }, { 22 | "type" : "record", 23 | "name" : "C", 24 | "fields" : [ { 25 | "name" : "c", 26 | "type" : "string" 27 | } ] 28 | } ] 29 | } ] 30 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/optional_sealed_trait_enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "OptionalSealedTraitEnum", 4 | "namespace": "com.sksamuel.avro4s.schema.EnumSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "cupcat", 8 | "type": [ 9 | "null", 10 | { 11 | "type": "enum", 12 | "name": "CupcatEnum", 13 | "namespace": "com.sksamuel.avro4s.schema", 14 | "symbols": [ 15 | "SnoutleyEnum", 16 | "CuppersEnum" 17 | ] 18 | } 19 | ] 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/optional_union.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "OptionalUnion", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "union", 8 | "type": [ 9 | "null", 10 | "int", 11 | "string" 12 | ] 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/options.avro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sksamuel/avro4s/e9c5772edf639b3178ed0fd352b89a17a4c5d835/avro4s-core/src/test/resources/options.avro -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/painters.avro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sksamuel/avro4s/e9c5772edf639b3178ed0fd352b89a17a4c5d835/avro4s-core/src/test/resources/painters.avro -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/props_annotation_class.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroPropSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "str", 8 | "type": "string" 9 | } 10 | ], 11 | "cold": "play" 12 | } 13 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/props_annotation_field.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroPropSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "str", 8 | "type": "string", 9 | "cold": "play" 10 | }, 11 | { 12 | "name": "long", 13 | "type": "long", 14 | "kate": "bush" 15 | }, 16 | { 17 | "name": "int", 18 | "type": "int" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/props_annotation_json_field.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroPropSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "str", 8 | "type": "string", 9 | "terms": [ 10 | "foo", 11 | "bar" 12 | ] 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/props_annotation_scala_enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Annotated", 4 | "namespace": "com.sksamuel.avro4s.schema.AvroPropSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "colours", 8 | "type": { 9 | "type": "enum", 10 | "name": "Colours", 11 | "namespace": "com.sksamuel.avro4s.schema", 12 | "symbols": [ 13 | "Red", 14 | "Amber", 15 | "Green" 16 | ] 17 | }, 18 | "cold": "play" 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/scala3_enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.EitherSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "a", 8 | "type": "string" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/schema_override_basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "OverrideTest", 4 | "namespace": "com.sksamuel.avro4s.schema.SchemaForTypeclassOverrideTest", 5 | "fields": [ 6 | { 7 | "name": "s", 8 | "type": { 9 | "type": "bytes", 10 | "foo": "bar" 11 | } 12 | }, 13 | { 14 | "name": "i", 15 | "type": "int" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/schema_override_complex.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "OverrideTest", 4 | "namespace": "com.sksamuel.avro4s.schema.SchemaForTypeclassOverrideTest", 5 | "fields": [ 6 | { 7 | "name": "s", 8 | "type": "string" 9 | }, 10 | { 11 | "name": "f", 12 | "type": { 13 | "type": "double", 14 | "foo": "bar" 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/schema_override_top_level_value_type.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "int", 3 | "foo": "bar" 4 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/schema_override_value_type.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "int", 3 | "foo": "bar" 4 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/scoped_implicits.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "Product", 4 | "namespace" : "com.sksamuel.avro4s", 5 | "fields" : [ { 6 | "name" : "name", 7 | "type" : "string" 8 | }, { 9 | "name" : "price", 10 | "type" : { 11 | "type" : "record", 12 | "name" : "Price", 13 | "namespace" : "com.sksamuel.avro4s", 14 | "fields" : [ { 15 | "name" : "currency", 16 | "type" : "string" 17 | }, { 18 | "name" : "amount", 19 | "type" : { 20 | "type" : "bytes", 21 | "logicalType" : "decimal", 22 | "precision" : 8, 23 | "scale" : 2 24 | } 25 | } ] 26 | } 27 | }, { 28 | "name" : "litres", 29 | "type" : { 30 | "type" : "bytes", 31 | "logicalType" : "decimal", 32 | "precision" : 8, 33 | "scale" : 3 34 | } 35 | } ] 36 | } 37 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/sealed_trait_enum_no_default.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "SealedTraitEnum", 4 | "namespace": "com.sksamuel.avro4s.schema.EnumSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "cupcat", 8 | "type": { 9 | "type": "enum", 10 | "name": "CupcatEnum", 11 | "namespace": "com.sksamuel.avro4s.schema", 12 | "symbols": [ 13 | "SnoutleyEnum", 14 | "CuppersEnum" 15 | ] 16 | } 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/sealed_trait_of_nested_objects.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Schema", 4 | "namespace": "com.sksamuel.avro4s.schema.SealedTraitSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "foo", 8 | "type": { 9 | "type": "enum", 10 | "name": "Foo", 11 | "symbols": [ 12 | "Bar", 13 | "Baz" 14 | ] 15 | } 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/sealed_trait_of_objects.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "enum", 3 | "name": "Dibble", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "symbols": [ 6 | "Dabble", 7 | "Dobble" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/sealed_traits.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Wrapper", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "wibble", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "Wabble", 12 | "fields": [ 13 | { 14 | "name": "dbl", 15 | "type": "double" 16 | } 17 | ] 18 | }, 19 | { 20 | "type": "record", 21 | "name": "Wobble", 22 | "fields": [ 23 | { 24 | "name": "str", 25 | "type": "string" 26 | } 27 | ] 28 | } 29 | ] 30 | } 31 | ] 32 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/seq.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "seq", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "string" 12 | } 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/seq2.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "SeqExample2", 4 | "namespace": "com.sksamuel.avro4s", 5 | "fields": [ 6 | { 7 | "name": "seq", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type" : "record", 12 | "name" : "SeqExample", 13 | "fields" : [ 14 | { 15 | "name" : "seq", 16 | "type" : { 17 | "type" : "array", 18 | "items" : "double" 19 | } 20 | } 21 | ] 22 | } 23 | } 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/seq3.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "SeqExample3", 4 | "namespace": "com.sksamuel.avro4s", 5 | "fields": [ 6 | { 7 | "name": "map", 8 | "type": { 9 | "type": "map", 10 | "values": "string" 11 | } 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/seq4.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "SeqExample4", 4 | "namespace" : "com.sksamuel.avro4s", 5 | "fields" : [ { 6 | "name" : "map", 7 | "type" : { 8 | "type" : "map", 9 | "values" : { 10 | "type" : "record", 11 | "name" : "SeqExample2", 12 | "fields" : [ { 13 | "name" : "seq", 14 | "type" : { 15 | "type" : "array", 16 | "items" : { 17 | "type" : "record", 18 | "name" : "SeqExample", 19 | "fields" : [ { 20 | "name" : "seq", 21 | "type" : { 22 | "type" : "array", 23 | "items" : "double" 24 | } 25 | } ] 26 | } 27 | } 28 | } ] 29 | } 30 | } 31 | } ] 32 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/seq_of_maps.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "seq", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "map", 12 | "values": "string" 13 | } 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/seqofmaps.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NestedSetDouble", 4 | "namespace": "com.sksamuel.avro4s", 5 | "fields": [ 6 | { 7 | "name": "set", 8 | "type": { 9 | "type": "array", 10 | "items" : { 11 | "type" : "double" 12 | } 13 | } 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/seqrecords.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "seq", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "record", 12 | "name": "Nested", 13 | "fields": [ 14 | { 15 | "name": "goo", 16 | "type": "string" 17 | } 18 | ] 19 | } 20 | } 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/setdoubles.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "NestedSetDouble", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "set", 8 | "type": { 9 | "type": "array", 10 | "items" : { 11 | "type" : "double" 12 | } 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/setrecords.json: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "NestedSet", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields" : [ { 6 | "name" : "set", 7 | "type" : { 8 | "type" : "array", 9 | "items" : { 10 | "type" : "record", 11 | "name" : "Nested", 12 | "fields" : [ { 13 | "name" : "goo", 14 | "type" : "string" 15 | } ] 16 | } 17 | } 18 | } ] 19 | } 20 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/setstrings.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "set", 8 | "type": { 9 | "type": "array", 10 | "items" : { 11 | "type" : "string" 12 | } 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/string.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.StringSchemasTest", 5 | "fields": [ 6 | { 7 | "name": "str", 8 | "type": "string" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/timestamp.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "TimestampTest", 4 | "namespace": "com.sksamuel.avro4s.schema.DateSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "ts", 8 | "type": { 9 | "type": "long", 10 | "logicalType": "timestamp-millis" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_boolean.json: -------------------------------------------------------------------------------- 1 | "boolean" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_byte_array.json: -------------------------------------------------------------------------------- 1 | "bytes" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_bytebuffer.json: -------------------------------------------------------------------------------- 1 | "bytes" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_class_namespace.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Tau", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "a", 8 | "type": "string" 9 | }, 10 | { 11 | "name": "b", 12 | "type": "boolean" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_double.json: -------------------------------------------------------------------------------- 1 | "double" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_float.json: -------------------------------------------------------------------------------- 1 | "float" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_integer.json: -------------------------------------------------------------------------------- 1 | "int" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_list_int.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": "int" 4 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_long.json: -------------------------------------------------------------------------------- 1 | "long" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_object_namespace.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "A", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "inner", 8 | "type": { 9 | "type": "record", 10 | "namespace": "com.sksamuel.avro4s.schema.A", 11 | "name": "Inner", 12 | "fields": [ 13 | { 14 | "name": "s", 15 | "type": "string" 16 | } 17 | ] 18 | } 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_package_object_namespace.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Sigma", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "a", 8 | "type": "string" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_sealed_trait.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "record", 4 | "name": "Nabble", 5 | "namespace": "com.sksamuel.avro4s.schema", 6 | "fields": [ 7 | { 8 | "name": "str", 9 | "type": "string" 10 | }, 11 | { 12 | "name": "age", 13 | "type": "int" 14 | } 15 | ] 16 | }, 17 | { 18 | "type": "record", 19 | "name": "Nobble", 20 | "namespace": "com.sksamuel.avro4s.schema", 21 | "fields": [ 22 | { 23 | "name": "str", 24 | "type": "string" 25 | }, 26 | { 27 | "name": "place", 28 | "type": "string" 29 | } 30 | ] 31 | } 32 | ] -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_seq_double.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": "double" 4 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_set_boolean.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": "boolean" 4 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_string.json: -------------------------------------------------------------------------------- 1 | "string" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/top_level_vector_string.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": "string" 4 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/trait_subtypes_duplicate_fields.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Trapper", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "tibble", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "Tabble", 12 | "fields": [ 13 | { 14 | "name": "str", 15 | "type": "double" 16 | }, 17 | { 18 | "name": "age", 19 | "type": "int" 20 | } 21 | ] 22 | }, 23 | { 24 | "type": "record", 25 | "name": "Tobble", 26 | "fields": [ 27 | { 28 | "name": "str", 29 | "type": "string" 30 | }, 31 | { 32 | "name": "place", 33 | "type": "string" 34 | } 35 | ] 36 | } 37 | ] 38 | } 39 | ] 40 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/trait_subtypes_duplicate_fields_same_type.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Napper", 4 | "namespace": "com.sksamuel.avro4s.schema", 5 | "fields": [ 6 | { 7 | "name": "nibble", 8 | "type": [ 9 | { 10 | "type": "record", 11 | "name": "Nabble", 12 | "fields": [ 13 | { 14 | "name": "str", 15 | "type": "string" 16 | }, 17 | { 18 | "name": "age", 19 | "type": "int" 20 | } 21 | ] 22 | }, 23 | { 24 | "type": "record", 25 | "name": "Nobble", 26 | "fields": [ 27 | { 28 | "name": "str", 29 | "type": "string" 30 | }, 31 | { 32 | "name": "place", 33 | "type": "string" 34 | } 35 | ] 36 | } 37 | ] 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/traits.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "record", 3 | "name" : "Wrapper", 4 | "namespace" : "com.sksamuel.avro4s", 5 | "fields" : [ { 6 | "name" : "wibble", 7 | "type" : { 8 | "type" : "record", 9 | "name" : "Wibble", 10 | "fields" : [ { 11 | "name" : "str", 12 | "type" : [ "string", "null" ] 13 | }, { 14 | "name" : "dbl", 15 | "type" : [ "double", "null" ] 16 | } ] 17 | } 18 | } ] 19 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/transient.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "TransientFoo", 4 | "namespace": "com.sksamuel.avro4s.schema.TransientSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "a", 8 | "type": "string" 9 | }, 10 | { 11 | "name": "c", 12 | "type": "string" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/tuple2.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test2", 4 | "namespace": "com.sksamuel.avro4s.schema.TupleSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "z", 8 | "type": { 9 | "type": "record", 10 | "name": "Tuple2", 11 | "namespace": "scala", 12 | "fields": [ 13 | { 14 | "name": "_1", 15 | "type": "string" 16 | }, 17 | { 18 | "name": "_2", 19 | "type": "int" 20 | } 21 | ] 22 | } 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/tuple3.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test3", 4 | "namespace": "com.sksamuel.avro4s.schema.TupleSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "z", 8 | "type": { 9 | "type": "record", 10 | "name": "Tuple3", 11 | "namespace": "scala", 12 | "fields": [ 13 | { 14 | "name": "_1", 15 | "type": "string" 16 | }, 17 | { 18 | "name": "_2", 19 | "type": "int" 20 | }, 21 | { 22 | "name": "_3", 23 | "type": "boolean" 24 | } 25 | ] 26 | } 27 | } 28 | ] 29 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/tuple4.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test4", 4 | "namespace": "com.sksamuel.avro4s.schema.TupleSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "z", 8 | "type": { 9 | "type": "record", 10 | "name": "Tuple4", 11 | "namespace": "scala", 12 | "fields": [ 13 | { 14 | "name": "_1", 15 | "type": "string" 16 | }, 17 | { 18 | "name": "_2", 19 | "type": "int" 20 | }, 21 | { 22 | "name": "_3", 23 | "type": "boolean" 24 | }, 25 | { 26 | "name": "_4", 27 | "type": "double" 28 | } 29 | ] 30 | } 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/tuple5.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test5", 4 | "namespace": "com.sksamuel.avro4s.schema.TupleSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "z", 8 | "type": { 9 | "type": "record", 10 | "name": "Tuple5", 11 | "namespace": "scala", 12 | "fields": [ 13 | { 14 | "name": "_1", 15 | "type": "string" 16 | }, 17 | { 18 | "name": "_2", 19 | "type": "int" 20 | }, 21 | { 22 | "name": "_3", 23 | "type": "boolean" 24 | }, 25 | { 26 | "name": "_4", 27 | "type": "double" 28 | }, 29 | { 30 | "name": "_5", 31 | "type": "long" 32 | } 33 | ] 34 | } 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/utf8.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Person", 4 | "namespace": "com.sksamuel.avro4s.schema.UtfSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "name", 8 | "type": "string" 9 | }, 10 | { 11 | "name": "alias", 12 | "type": "string" 13 | }, 14 | { 15 | "name": "age", 16 | "type": "int" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/uuid.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "UUIDTest", 4 | "namespace": "com.sksamuel.avro4s.schema.UUIDSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "uuid", 8 | "type": { 9 | "type": "string", 10 | "logicalType": "uuid" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/uuid_default.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "UUIDDefault", 4 | "namespace": "com.sksamuel.avro4s.schema.UUIDSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "uuid", 8 | "type": { 9 | "type": "string", 10 | "logicalType": "uuid" 11 | }, 12 | "default": "86da265c-95bd-443c-8860-9381efca059d" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/uuid_option.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "UUIDOption", 4 | "namespace": "com.sksamuel.avro4s.schema.UUIDSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "uuid", 8 | "type": [ 9 | "null", 10 | { 11 | "type": "string", 12 | "logicalType": "uuid" 13 | } 14 | ] 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/uuid_seq.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "UUIDSeq", 4 | "namespace": "com.sksamuel.avro4s.schema.UUIDSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "uuids", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "string", 12 | "logicalType": "uuid" 13 | } 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/value_class_nested.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Wibble", 4 | "namespace": "com.sksamuel.avro4s.schema.ValueTypeSchemaTest", 5 | "fields": [ 6 | { 7 | "name": "value", 8 | "type": "string" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/value_class_top_level.json: -------------------------------------------------------------------------------- 1 | "string" -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/vector_of_maps.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "Test", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "vector", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "map", 12 | "values": "string" 13 | } 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/vector_prim.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "VectorPrim", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "booleans", 8 | "type": { 9 | "type": "array", 10 | "items": "boolean" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /avro4s-core/src/test/resources/vector_records.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "VectorRecord", 4 | "namespace": "com.sksamuel.avro4s.schema.ArraySchemaTest", 5 | "fields": [ 6 | { 7 | "name": "records", 8 | "type": { 9 | "type": "array", 10 | "items": { 11 | "type": "record", 12 | "name": "Record", 13 | "fields": [ 14 | { 15 | "name": "str", 16 | "type": "string" 17 | }, 18 | { 19 | "name": "double", 20 | "type": "double" 21 | } 22 | ] 23 | } 24 | } 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/Recursive.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | //import shapeless.{:+:, CNil} 4 | 5 | //sealed trait Tree[+T] 6 | //case class Branch[+T](left: Tree[T], right: Tree[T]) extends Tree[T] 7 | //case class Leaf[+T](value: T) extends Tree[T] 8 | 9 | object Recursive { 10 | 11 | case class MutRec1(payload: Int, children: List[MutRec2]) 12 | case class MutRec2(payload: String, children: List[MutRec1]) 13 | 14 | case class ListTree[+T](value: T, children: Seq[ListTree[T]] = Seq.empty) 15 | case class MapTree[+T](value: T, children: Map[String, MapTree[T]] = Map.empty[String, MapTree[T]]) 16 | case class OptionTree[T](value: T, left: Option[OptionTree[T]] = None, right: Option[OptionTree[T]] = None) 17 | 18 | type EitherTree[T] = Either[EitherBranch[T], EitherLeaf[T]] 19 | case class EitherLeaf[T](value: T) 20 | case class EitherBranch[T](left: EitherTree[T], right: EitherTree[T]) 21 | 22 | // type CoproductTree[T] = CBranch[T] :+: CLeaf[T] :+: CNil 23 | // case class CLeaf[T](value: T) 24 | // case class CBranch[T](left: CoproductTree[T], right: CoproductTree[T]) 25 | 26 | sealed trait TVTree[+T] 27 | case class TreeValue[T](tree: TVTree[T]) extends AnyVal 28 | case class TVBranch[T](left: (Int, TreeValue[T]), right: (Int, TreeValue[T])) extends TVTree[T] 29 | case class TVLeaf[T](value: T) extends TVTree[T] 30 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/examples/Examples.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.examples 2 | // 3 | //import java.io.ByteArrayOutputStream 4 | // 5 | //import org.scalatest.{Matchers, WordSpec} 6 | // 7 | //class Examples extends WordSpec with Matchers { 8 | // import com.sksamuel.avro4s.AvroOutputStream 9 | // 10 | // case class Ingredient(name: String, sugar: Double, fat: Double) 11 | // case class Pizza(name: String, ingredients: Seq[Ingredient], vegetarian: Boolean, vegan: Boolean, calories: Int) 12 | // 13 | // val pepperoni = Pizza("pepperoni", Seq(Ingredient("pepperoni", 12, 4.4), Ingredient("onions", 1, 0.4)), false, false, 98) 14 | // val hawaiian = Pizza("hawaiian", Seq(Ingredient("ham", 1.5, 5.6), Ingredient("pineapple", 5.2, 0.2)), false, false, 91) 15 | // 16 | // "AvroStream" should { 17 | // 18 | // "read back the objects " in { 19 | // val bos = new ByteArrayOutputStream() 20 | // 21 | // val os = AvroOutputStream.data[Pizza](bos) 22 | // os.write(Seq(pepperoni, hawaiian)) 23 | // os.flush() 24 | // os.close() 25 | // 26 | // import com.sksamuel.avro4s.AvroInputStream 27 | // 28 | // val is = AvroInputStream.data[Pizza](bos.toByteArray) 29 | // val pizzas = is.iterator.toSeq 30 | // is.close() 31 | // 32 | // pizzas shouldBe Seq(pepperoni, hawaiian) 33 | // } 34 | // } 35 | // 36 | //} 37 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/examples/UppercasePkg/ClassInUppercasePackage.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.examples.UppercasePkg 2 | 3 | case class ClassInUppercasePackage(s: String) 4 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/Github254.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.github 2 | 3 | import com.sksamuel.avro4s.AvroSchema 4 | import org.scalatest.funsuite.AnyFunSuite 5 | import org.scalatest.matchers.should.Matchers 6 | 7 | class Github254 extends AnyFunSuite with Matchers { 8 | 9 | case class A(c: C) 10 | case class B(as: List[A]) 11 | 12 | sealed trait C 13 | case object c1 extends C 14 | case object c2 extends C 15 | 16 | test("NoClassDefFoundError for case class wrapping sealed trait (regression?) #254") { 17 | AvroSchema[A].toString(true) shouldBe new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github254_a.json")).toString(true) 18 | AvroSchema[List[A]].toString(true) shouldBe new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github254_lista.json")).toString(true) 19 | AvroSchema[B].toString(true) shouldBe new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github254_b.json")).toString(true) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/Github265.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.{Decoder, Encoder, RecordFormat} 4 | //import org.apache.avro.generic.GenericRecord 5 | //import org.scalatest.funsuite.AnyFunSuite 6 | //import org.scalatest.matchers.should.Matchers 7 | // 8 | //import scala.language.higherKinds 9 | // 10 | //class Github265 extends AnyFunSuite with Matchers { 11 | // 12 | // case class Ingredient(name: String, sugar: Double, fat: Double) 13 | // case class Pizza(name: String, ingredients: Seq[Ingredient], vegetarian: Boolean, vegan: Boolean, calories: Int) 14 | // 15 | // val pepperoni = Pizza("pepperoni", Seq(Ingredient("pepperoni", 12, 4.4), Ingredient("onions", 1, 0.4)), false, false, 98) 16 | // val hawaiian = Pizza("hawaiian", Seq(Ingredient("ham", 1.5, 5.6), Ingredient("pineapple", 5.2, 0.2)), false, false, 91) 17 | // 18 | // def toAvro[T: Encoder : Decoder](obj: T): GenericRecord = RecordFormat[T].to(obj) 19 | // 20 | // val recordInAvro = toAvro[Pizza](pepperoni) 21 | // printf(s"Avro of Pepperoni: $recordInAvro\n") 22 | //} 23 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/Github273.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.SchemaFor 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | //import shapeless.{:+:, CNil} 7 | // 8 | //case class Coproducts(cp: Int :+: String :+: Boolean :+: CNil) 9 | //case class CoproductOfCoproductsField(cp: Coproducts :+: Boolean :+: CNil) 10 | // 11 | //class Github273 extends AnyFunSuite with Matchers { 12 | // 13 | // test("Diverging implicit expansion for SchemaFor in Coproducts inside case classes #273") { 14 | // SchemaFor[CoproductOfCoproductsField] 15 | // } 16 | //} 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/Github292.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.SchemaFor 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | // 7 | //case class Payload[A](value: A) 8 | // 9 | //sealed trait Complex 10 | // 11 | //sealed trait InvertibleComplex extends Complex 12 | // 13 | //case class Foo(value: String, payload: Payload[String]) extends InvertibleComplex 14 | // 15 | //case class Bar(value: Int) extends InvertibleComplex 16 | // 17 | //case class InvertibleComplexWrapper(unwrap: InvertibleComplex) 18 | // 19 | //case class Invert(i: InvertibleComplexWrapper) extends Complex 20 | // 21 | //class Github292 extends AnyFunSuite with Matchers { 22 | // test("Introducing type-parametrised values breaks derivation for some ADTs #292") { 23 | // SchemaFor[Complex].schema.toString(true) shouldBe new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github292.json")).toString(true) 24 | // } 25 | //} 26 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/Github295.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.SchemaFor 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | // 7 | //sealed trait InnerTrait295 8 | //case class InnerTraitConcrete295(v: Int) extends InnerTrait295 9 | //case class InnerTraitConcrete295_2(v: Int) extends InnerTrait295 10 | // 11 | //sealed trait OuterTrait295 12 | //case class OuterConcrete295(inner: InnerTrait295) extends OuterTrait295 13 | // 14 | //class Github295 extends AnyFunSuite with Matchers { 15 | // test("Cannot generate schema for a sealed trait, which concrete case class has another sealed trait as an argument #295") { 16 | // val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github295.json")) 17 | // SchemaFor[OuterTrait295].schema.toString(true) shouldBe expected.toString(true) 18 | // } 19 | //} 20 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/Github318.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.SchemaFor 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | //import shapeless.{:+:, CNil} 7 | // 8 | //sealed trait MyAdt 9 | //object MyAdt { 10 | // case class Foo(name: String) extends MyAdt 11 | // case class Bar(id: Int) extends MyAdt 12 | //} 13 | //case class CoproductWithAdt(cp: MyAdt :+: Boolean :+: CNil) 14 | // 15 | //class Github318 extends AnyFunSuite with Matchers { 16 | // 17 | // test("Error getting SchemaFor instance for Coproduct with ADT #318") { 18 | // val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github/github_318.json")) 19 | // SchemaFor[CoproductWithAdt].schema.toString(true) shouldBe expected.toString(true) 20 | // } 21 | //} 22 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/Github408.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.streams.input.InputStreamTest 4 | // 5 | //case class Woo(b: Boolean) 6 | //case class OptionOfSeqOfCaseClass(ws: Option[Seq[Woo]]) 7 | // 8 | //class Github408 extends InputStreamTest { 9 | // 10 | // test("round trip of Option[Seq[CaseClass]]") { 11 | // writeRead(OptionOfSeqOfCaseClass(Some(List(Woo(true), Woo(false), Woo(true))))) 12 | // } 13 | //} 14 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/Github411.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.SchemaFor 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | // 7 | //class Github411 extends AnyFunSuite with Matchers { 8 | // 9 | // case class DefaultOfDefault(value: String) 10 | // case class DefaultValue(property: DefaultOfDefault = DefaultOfDefault("some-default")) 11 | // case class Github411Class(property: DefaultValue = DefaultValue()) 12 | // 13 | // test("schema generation with defaults in defaults") { 14 | // SchemaFor[Github411Class].schema.toString(true) 15 | // } 16 | //} -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/Github415.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import java.io.{FileOutputStream, ObjectOutputStream} 4 | // 5 | //import com.sksamuel.avro4s.Encoder 6 | //import com.sksamuel.avro4s.github.Github415.PlaybackSession 7 | //import org.scalatest.funsuite.AnyFunSuite 8 | //import org.scalatest.matchers.must.Matchers 9 | // 10 | //class Github415 extends AnyFunSuite with Matchers { 11 | // 12 | // test("github 415") { 13 | // val fileOut = new FileOutputStream("remove_me") 14 | // val out = new ObjectOutputStream(fileOut) 15 | // out.writeObject(Encoder[PlaybackSession]) 16 | // } 17 | //} 18 | // 19 | //object Github415 { 20 | // object Rebuffers { 21 | // case class Metrics(count: Int) 22 | // case class EarlyLate(early: Metrics) 23 | // case class Stats(session: Option[EarlyLate]) 24 | // } 25 | // 26 | // case class Rebuffers(network: Option[Rebuffers.Stats]) 27 | // 28 | // case class PlaybackSession(rebuffers: Option[Rebuffers]) 29 | //} -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue110.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.RecordFormat 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | // 7 | //case class P1(name: String, age: Int = 18) 8 | //case class P2(name: String) 9 | // 10 | //class GithubIssue110 extends AnyFunSuite with Matchers { 11 | // 12 | // test("default value should be picked up") { 13 | // val f1 = RecordFormat[P1] 14 | // val f2 = RecordFormat[P2] 15 | // f1.from(f2.to(P2("foo"))) shouldBe P1("foo") 16 | // } 17 | //} 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue193.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.github 2 | 3 | import java.io.ByteArrayOutputStream 4 | 5 | import com.sksamuel.avro4s.{AvroFixed, AvroInputStream, AvroOutputStream} 6 | import org.scalatest.funsuite.AnyFunSuite 7 | import org.scalatest.matchers.should.Matchers 8 | 9 | case class Data(uuid: Option[UUID]) 10 | case class UUID(@AvroFixed(8) bytes: Array[Byte]) 11 | 12 | class GithubIssue193 extends AnyFunSuite with Matchers { 13 | 14 | test("Converting data with an optional fixed type field to GenericRecord fails #193") { 15 | 16 | val baos = new ByteArrayOutputStream() 17 | 18 | val output = AvroOutputStream.data[Data].to(baos).build() 19 | output.write(Data(Some(UUID(Array[Byte](0, 1, 2, 3, 4, 5, 6, 7))))) 20 | output.write(Data(None)) 21 | output.write(Data(Some(UUID(Array[Byte](7, 6, 5, 4, 3, 2, 1, 0))))) 22 | output.close() 23 | 24 | val input = AvroInputStream.data[Data].from(baos.toByteArray).build 25 | val datas = input.iterator.toList 26 | datas.head.uuid.get.bytes should equal(Array[Byte](0, 1, 2, 3, 4, 5, 6, 7)) 27 | datas(1).uuid shouldBe None 28 | datas.last.uuid.get.bytes should equal(Array[Byte](7, 6, 5, 4, 3, 2, 1, 0)) 29 | input.close() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue205.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.github 2 | 3 | import org.scalatest.matchers.should.Matchers 4 | import org.scalatest.wordspec.AnyWordSpec 5 | 6 | class GithubIssue205 extends AnyWordSpec with Matchers { 7 | 8 | "SchemaFor" should { 9 | "work for case classes with complete path and no default value" in { 10 | """ 11 | import com.sksamuel.avro4s.SchemaFor 12 | SchemaFor[com.sksamuel.avro4s.github.TestModel.Clazz1] 13 | """ should compile 14 | } 15 | 16 | "work for case classes with complete path and default value" in { 17 | """ 18 | import com.sksamuel.avro4s.SchemaFor 19 | SchemaFor[com.sksamuel.avro4s.github.TestModel.Clazz2] 20 | """ should compile 21 | } 22 | 23 | "work for case classes with import and no default value" in { 24 | """ 25 | import com.sksamuel.avro4s.SchemaFor 26 | import com.sksamuel.avro4s.github.TestModel._ 27 | SchemaFor[Clazz1] 28 | """ should compile 29 | } 30 | 31 | "work for case classes with import and default value" in { 32 | """ 33 | import com.sksamuel.avro4s.SchemaFor 34 | import com.sksamuel.avro4s.github.TestModel._ 35 | SchemaFor[Clazz2] 36 | """ should compile 37 | } 38 | } 39 | 40 | } 41 | 42 | object TestModel { 43 | case class Clazz1(str: String) 44 | case class Clazz2(str: String = "test") 45 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue234.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s._ 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | // 7 | //case class TestEntry(name: String) 8 | //sealed trait TestClass // class or trait 9 | //final case class Test(id: Int, entries: List[TestEntry]) extends TestClass // <-- list 10 | //case class ContainsTestClass(testClass: TestClass) 11 | // 12 | //class GithubIssue234 extends AnyFunSuite with Matchers { 13 | // 14 | // test("RecordFormat macro for List - diverging implicit expansion for type #234") { 15 | // val format: RecordFormat[ContainsTestClass] = RecordFormat[ContainsTestClass] 16 | // } 17 | //} 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue247.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.github 2 | 3 | import com.sksamuel.avro4s.{AvroSchema, Decoder, Encoder} 4 | import org.scalatest.funsuite.AnyFunSuite 5 | import org.scalatest.matchers.should.Matchers 6 | 7 | case class B(b: Map[String, String]) 8 | 9 | case class A(a: Seq[B]) 10 | 11 | class GithubIssue247 extends AnyFunSuite with Matchers { 12 | test("Diverging implicit expansion error on case class #247") { 13 | AvroSchema[A] 14 | Encoder[A] 15 | Decoder[A] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue330.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.AvroSchema 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | // 7 | //class GithubIssue330 extends AnyFunSuite with Matchers { 8 | // 9 | // test("Unable to generate schema for a CoProduct where on of the case class has a parameter of type Map[String, String]") { 10 | // val schema = AvroSchema[Foo330] 11 | // val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github/github_330.json")) 12 | // schema.toString(true) shouldBe expected.toString(true) 13 | // } 14 | //} 15 | // 16 | //sealed trait KeySetting 17 | //final case class ForeignKeySetting(targetEntityCode: String, 18 | // targetFieldName: String) extends KeySetting 19 | //final case class PrimaryKeySetting(attributes: Map[String, Int]) extends KeySetting 20 | // 21 | //case class Foo330(values: List[KeySetting]) -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue331.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.{AvroDoc, AvroSchema} 4 | //import org.scalatest.{FunSuite, Matchers} 5 | //import shapeless.{:+:, CNil} 6 | // 7 | //class GithubIssue331 extends FunSuite with Matchers { 8 | // 9 | // test("AvroDoc annotation and shapeless coproducts #331") { 10 | // val schema = AvroSchema[MyCaseClass] 11 | // val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github/github_331.json")) 12 | // schema.toString(true) shouldBe expected.toString(true) 13 | // } 14 | //} 15 | // 16 | //@AvroDoc("my doc") 17 | //case class MyCaseClass(myCoproduct: String :+: Int :+: CNil) -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue346.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.{AvroName, AvroNamespace, AvroSchema} 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | // 7 | //class GithubIssue346 extends AnyFunSuite with Matchers { 8 | // 9 | // test("Enum annotations failing #346") { 10 | // val schema = AvroSchema[MyEnum] 11 | // val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github/github_346.json")) 12 | // schema.toString(true) shouldBe expected.toString(true) 13 | // } 14 | //} 15 | // 16 | //@AvroNamespace("com.foo") 17 | //@AvroName("MyRenamedEnum") 18 | //sealed trait MyEnum 19 | //case object Hussel extends MyEnum 20 | //case object Bussel extends MyEnum 21 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue432.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream} 4 | // 5 | //import com.sksamuel.avro4s.Encoder 6 | //import org.scalatest.funsuite.AnyFunSuite 7 | // 8 | //class GithubIssue432 extends AnyFunSuite { 9 | // 10 | // test("Serializable Encoder[BigDecimal] #432") { 11 | // val oos = new ObjectOutputStream(new ByteArrayOutputStream()) 12 | // oos.writeObject(Encoder.bigDecimalEncoder) 13 | // oos.close() 14 | // } 15 | // 16 | // test("Deserialized Encoder[BigDecimal] works") { 17 | // val baos = new ByteArrayOutputStream() 18 | // val oos = new ObjectOutputStream(baos) 19 | // oos.writeObject(Encoder.bigDecimalEncoder) 20 | // oos.close() 21 | // 22 | // val ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray)) 23 | // val encoder = ois.readObject().asInstanceOf[Encoder[BigDecimal]] 24 | // 25 | // encoder.encode(12.34) 26 | // } 27 | //} 28 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue484.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream} 4 | // 5 | //import com.sksamuel.avro4s.record.decoder.ScalaEnumClass 6 | //import com.sksamuel.avro4s.schema.Colours 7 | //import com.sksamuel.avro4s.{AvroSchema, Decoder, DefaultFieldMapper} 8 | //import org.apache.avro.generic.GenericData 9 | //import org.apache.avro.generic.GenericData.EnumSymbol 10 | //import org.scalatest.funsuite.AnyFunSuite 11 | //import org.scalatest.matchers.should.Matchers 12 | // 13 | //class GithubIssue484 extends AnyFunSuite with Matchers { 14 | // 15 | // test("Serializable Scala Enum Decoder #484") { 16 | // val baos = new ByteArrayOutputStream() 17 | // val oos = new ObjectOutputStream(baos) 18 | // oos.writeObject(Decoder[ScalaEnumClass]) 19 | // oos.close() 20 | // 21 | // val decoder = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray)) 22 | // .readObject() 23 | // .asInstanceOf[Decoder[ScalaEnumClass]] 24 | // 25 | // val schema = AvroSchema[ScalaEnumClass] 26 | // val record = new GenericData.Record(schema) 27 | // record.put("colour", new EnumSymbol(schema.getField("colour").schema(), "Green")) 28 | // decoder.decode(record) shouldBe ScalaEnumClass(Colours.Green) 29 | // } 30 | //} 31 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue485.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream} 4 | // 5 | //import com.sksamuel.avro4s.record.decoder.CPWrapper 6 | //import com.sksamuel.avro4s.{AvroSchema, Decoder, DefaultFieldMapper} 7 | //import org.apache.avro.generic.GenericData 8 | //import org.apache.avro.util.Utf8 9 | //import org.scalatest.funsuite.AnyFunSuite 10 | //import org.scalatest.matchers.should.Matchers 11 | //import shapeless.Coproduct 12 | // 13 | //class GithubIssue485 extends AnyFunSuite with Matchers { 14 | // 15 | // test("Serializable Coproduct Decoder #485") { 16 | // val baos = new ByteArrayOutputStream() 17 | // val oos = new ObjectOutputStream(baos) 18 | // oos.writeObject(Decoder[CPWrapper]) 19 | // oos.close() 20 | // 21 | // val decoder = 22 | // new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray)).readObject().asInstanceOf[Decoder[CPWrapper]] 23 | // 24 | // val schema = AvroSchema[CPWrapper] 25 | // val record = new GenericData.Record(schema) 26 | // record.put("u", new Utf8("wibble")) 27 | // decoder.decode(record) shouldBe CPWrapper(Coproduct[CPWrapper.ISBG]("wibble")) 28 | // } 29 | //} 30 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue510.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream} 4 | // 5 | //import com.sksamuel.avro4s.record.decoder.CPWrapper 6 | //import com.sksamuel.avro4s.{AvroOutputStream, AvroSchema, Decoder} 7 | //import org.apache.avro.generic.GenericData 8 | //import org.apache.avro.util.Utf8 9 | //import org.scalatest.funsuite.AnyFunSuite 10 | //import org.scalatest.matchers.should.Matchers 11 | //import shapeless.Coproduct 12 | // 13 | //class GithubIssue510 extends AnyFunSuite with Matchers { 14 | // 15 | // test("AvroOutputStream should work for Vector[Int] #510") { 16 | // val obj = Vector[Int](1) 17 | // val byteStr = new java.io.ByteArrayOutputStream 18 | // val avroStr = AvroOutputStream.binary[Vector[Int]].to(byteStr).build() 19 | // avroStr.write(obj) 20 | // avroStr.close() 21 | // 22 | // println(byteStr.toByteArray.map("%02X" format _).mkString) 23 | // } 24 | //} 25 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue545.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.github 2 | 3 | import com.sksamuel.avro4s.{AvroSchema, Decoder, TypeGuardedDecoding} 4 | import org.scalatest.matchers.should.Matchers 5 | import org.scalatest.wordspec.AnyWordSpec 6 | 7 | import scala.collection.JavaConverters._ 8 | 9 | class GithubIssue545 extends AnyWordSpec with Matchers { 10 | "TypeGuardedDecoding" should { 11 | "create a map decoder instead of an array decoder" in { 12 | 13 | val mapDecoder = Decoder[Map[String, String]] 14 | val schema = AvroSchema[Map[String, String]] 15 | val typeGuard = TypeGuardedDecoding[Map[String, String]].guard(schema) 16 | val value = Map().asJava 17 | 18 | typeGuard.isDefinedAt(value) shouldBe true 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/github/GithubIssue69.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.github 2 | // 3 | //import com.sksamuel.avro4s.AvroSchema 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | // 7 | //import scala.language.higherKinds 8 | // 9 | //case class Message[T](payload: T, identity: String = "5b16ca84-f9e1-46a9-bc5c-8c0052b6dd16") 10 | //case class MyRecord(key: String, str1: String, str2: String, int1: Int) 11 | // 12 | //class GithubIssue69 extends AnyFunSuite with Matchers { 13 | // 14 | // test("Can't create schema for generic type #69") { 15 | // val schema = AvroSchema[Message[MyRecord]] 16 | // val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/github69.json")) 17 | // schema.toString(true) shouldBe expected.toString(true) 18 | // } 19 | //} 20 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/BigDecimalRoundTrip.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.record 2 | 3 | import com.sksamuel.avro4s.record.decoder.WithBigDecimal 4 | import com.sksamuel.avro4s.{AvroSchema, Decoder, Encoder, ScalePrecision, SchemaFor} 5 | import org.scalatest.funsuite.AnyFunSuite 6 | import org.scalatest.matchers.should.Matchers 7 | 8 | class BigDecimalRoundTrip extends AnyFunSuite with Matchers { 9 | 10 | test("BigDecimal round trip") { 11 | 12 | case class WithBigDecimal(decimal: BigDecimal) 13 | 14 | given ScalePrecision = ScalePrecision(3, 9) 15 | val schema = AvroSchema[WithBigDecimal] 16 | 17 | val encoded1 = Encoder[WithBigDecimal].encode(schema).apply(WithBigDecimal(BigDecimal(123.45))) 18 | val result1 = Decoder[WithBigDecimal].decode(schema).apply(encoded1) 19 | result1.decimal shouldBe BigDecimal(123.450) // will be padded to 3 dp 20 | 21 | val encoded2 = Encoder[WithBigDecimal].encode(schema).apply(WithBigDecimal(BigDecimal(123.4567))) 22 | val result2 = Decoder[WithBigDecimal].decode(schema).apply(encoded2) 23 | result2.decimal shouldBe BigDecimal(123.457) // will be rounded up 24 | 25 | val encoded3 = Encoder[WithBigDecimal].encode(schema).apply(WithBigDecimal(BigDecimal(123.456))) 26 | val result3 = Decoder[WithBigDecimal].decode(schema).apply(encoded3) 27 | result3.decimal shouldBe BigDecimal(123.456) // uses exactly 3 decimals 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/FromRecordTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.record 2 | 3 | import com.sksamuel.avro4s.{AvroSchema, FromRecord} 4 | import org.apache.avro.generic.GenericData 5 | import org.scalatest.matchers.should.Matchers 6 | import org.scalatest.wordspec.AnyWordSpec 7 | 8 | case class HasSomeFields(str: String, int: Int, boolean: Boolean, nested: Nested) 9 | case class Nested(foo: String) 10 | case class HasLessFields(str: String, boolean: Boolean, nested: Nested) 11 | 12 | class FromRecordTest extends AnyWordSpec with Matchers { 13 | 14 | "FromRecord" should { 15 | "decode to class with a subset of fields used to encode" in { 16 | val schema = AvroSchema[HasSomeFields] 17 | val nestedSchema = AvroSchema[Nested] 18 | 19 | val record = new GenericData.Record(schema) 20 | val nestedRecord = new GenericData.Record(nestedSchema) 21 | record.put("str", "hello") 22 | record.put("int", 42) 23 | record.put("boolean", false) 24 | nestedRecord.put("foo", "there") 25 | record.put("nested", nestedRecord) 26 | 27 | FromRecord[HasLessFields](schema).from(record) shouldBe HasLessFields("hello", false, Nested("there")) 28 | } 29 | } 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/ToRecordTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.record 2 | 3 | import com.sksamuel.avro4s.{AvroNamespace, AvroSchema, FromRecord, ToRecord} 4 | import org.apache.avro.generic.{GenericData, GenericRecord} 5 | import org.apache.avro.util.Utf8 6 | import org.scalatest.funsuite.AnyFunSuite 7 | import org.scalatest.matchers.should.Matchers 8 | 9 | sealed trait Foo 10 | case class Bar(i: Int) extends Foo 11 | case class Baz(s: String) extends Foo 12 | 13 | case class MySchema(@AvroNamespace("broken") foo: Foo, id: String, x: Int) 14 | 15 | class ToRecordTest extends AnyFunSuite with Matchers { 16 | 17 | test("encode to record") { 18 | val schema = AvroSchema[HasSomeFields] 19 | val record = ToRecord[HasSomeFields](schema).to(HasSomeFields("hello", 42, false, Nested("there"))) 20 | record.get("str") shouldBe new Utf8("hello") 21 | record.get("int").asInstanceOf[Int] shouldBe 42 22 | record.get("boolean").asInstanceOf[Boolean] shouldBe false 23 | record.get("nested").asInstanceOf[GenericRecord].get("foo") shouldBe new Utf8("there") 24 | } 25 | 26 | // test("ToRecord should work with a namespace annotation on an ADT") { 27 | // val schema = AvroSchema[MySchema] 28 | // val ms = MySchema(Bar(1), "", 0) 29 | // ToRecord[MySchema](schema).to(ms) 30 | // } 31 | } 32 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/decoder/AvroNameDecoderTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.record.decoder 2 | 3 | import com.sksamuel.avro4s.{AvroName, AvroSchema, Decoder, DefaultFieldMapper, FieldMapper} 4 | import org.apache.avro.generic.GenericData 5 | import org.apache.avro.util.Utf8 6 | import org.scalatest.funsuite.AnyFunSuite 7 | import org.scalatest.matchers.should.Matchers 8 | 9 | case class Test123(@AvroName("bar") foo: String) 10 | 11 | class AvroNameDecoderTest extends AnyFunSuite with Matchers { 12 | 13 | test("decoder should take into account @AvroName on fields") { 14 | val schema = AvroSchema[Test123] 15 | val record = new GenericData.Record(schema) 16 | record.put("bar", new Utf8("hello")) 17 | val decoder = Decoder[Test123] 18 | decoder.decode(schema).apply(record) shouldBe Test123("hello") 19 | } 20 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/decoder/FieldMapperDecoderTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.record.decoder 2 | // 3 | //import com.sksamuel.avro4s.record.encoder.NamingTest 4 | //import com.sksamuel.avro4s.{AvroSchema, Decoder, FieldMapper, SchemaFor, SnakeCase} 5 | //import org.apache.avro.generic.GenericData 6 | //import org.scalatest.funsuite.AnyFunSuite 7 | //import org.scalatest.matchers.should.Matchers 8 | // 9 | //class FieldMapperDecoderTest extends AnyFunSuite with Matchers { 10 | // 11 | // test("fieldMapper should override the field names in a decoder") { 12 | // implicit val fieldMapper: FieldMapper = SnakeCase 13 | // val schema = AvroSchema[NamingTest] 14 | // val decoder = Decoder[NamingTest] 15 | // val record = new GenericData.Record(schema) 16 | // record.put("camel_case", "foo") 17 | // val result = decoder.decode(record) 18 | // result shouldBe NamingTest("foo") 19 | // } 20 | //} 21 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/decoder/FixedDecoderTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.record.decoder 2 | 3 | import com.sksamuel.avro4s.record.encoder.FixedValueType 4 | import com.sksamuel.avro4s.{AvroFixed, AvroSchema, Decoder} 5 | import org.apache.avro.generic.GenericData 6 | import org.scalatest.funsuite.AnyFunSuite 7 | import org.scalatest.matchers.should.Matchers 8 | 9 | class FixedDecoderTest extends AnyFunSuite with Matchers { 10 | 11 | case class FixedString(@AvroFixed(10) z: String) 12 | case class OptionalFixedValueType(z: Option[FixedValueType]) 13 | 14 | test("decode bytes to String") { 15 | val schema = AvroSchema[FixedString] 16 | val record = new GenericData.Record(schema) 17 | record.put("z", Array[Byte](115, 97, 109)) 18 | Decoder[FixedString].decode(schema).apply(record) shouldBe FixedString("sam") 19 | } 20 | 21 | // test("support options of fixed") { 22 | // val schema = AvroSchema[OptionalFixedValueType] 23 | // val record = new GenericData.Record(schema) 24 | // record.put("z", new GenericData.Fixed(AvroSchema[FixedValueType], Array[Byte](115, 97, 109))) 25 | // Decoder[OptionalFixedValueType].decode(record) shouldBe OptionalFixedValueType(Some(FixedValueType("sam"))) 26 | // } 27 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/decoder/TransientDecoderTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.record.decoder 2 | 3 | import com.sksamuel.avro4s.{AvroSchema, AvroTransient, Decoder} 4 | import org.apache.avro.generic.GenericData 5 | import org.apache.avro.util.Utf8 6 | import org.scalatest.funsuite.AnyFunSuite 7 | import org.scalatest.matchers.should.Matchers 8 | 9 | class TransientDecoderTest extends AnyFunSuite with Matchers { 10 | 11 | case class TransientFoo(a: String, @AvroTransient b: Option[String]) 12 | 13 | test("decoder should populate transient fields with None") { 14 | val schema = AvroSchema[TransientFoo] 15 | val record = new GenericData.Record(schema) 16 | record.put("a", new Utf8("hello")) 17 | Decoder[TransientFoo].decode(schema).apply(record) shouldBe TransientFoo("hello", None) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/decoder/ValueTypeDecoderTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.record.decoder 2 | // 3 | //import com.sksamuel.avro4s.{AvroSchema, Decoder} 4 | //import org.apache.avro.generic.GenericData 5 | //import org.apache.avro.util.Utf8 6 | //import org.scalatest.funsuite.AnyFunSuite 7 | //import org.scalatest.matchers.should.Matchers 8 | // 9 | //class ValueTypeDecoderTest extends AnyFunSuite with Matchers { 10 | // 11 | // case class Test(foo: FooValueType) 12 | // case class OptionTest(foo: Option[FooValueType]) 13 | // 14 | // test("top level value types") { 15 | // val actual = Decoder[FooValueType].decode("hello") 16 | // actual shouldBe FooValueType("hello") 17 | // } 18 | // 19 | // test("support fields that are value types") { 20 | // val schema = AvroSchema[Test] 21 | // 22 | // val record1 = new GenericData.Record(schema) 23 | // record1.put("foo", new Utf8("hello")) 24 | // 25 | // Decoder[Test].decode(record1) shouldBe Test(FooValueType("hello")) 26 | // } 27 | // 28 | // test("support value types inside Options") { 29 | // val schema = AvroSchema[OptionTest] 30 | // 31 | // val record1 = new GenericData.Record(schema) 32 | // record1.put("foo", new Utf8("hello")) 33 | // 34 | // Decoder[OptionTest].decode(record1) shouldBe OptionTest(Some(FooValueType("hello"))) 35 | // } 36 | //} 37 | // 38 | //case class FooValueType(s: String) extends AnyVal 39 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/encoder/AvroTransientEncoderTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.record.encoder 2 | // 3 | //import com.sksamuel.avro4s.{AvroTransient, Encoder, ImmutableRecord} 4 | //import org.apache.avro.util.Utf8 5 | //import org.scalatest.funsuite.AnyFunSuite 6 | //import org.scalatest.matchers.should.Matchers 7 | // 8 | //class AvroTransientEncoderTest extends AnyFunSuite with Matchers { 9 | // 10 | // test("encoder should skip @AvroTransient fields") { 11 | // case class Foo(a: String, @AvroTransient b: String, c: String) 12 | // val record = Encoder[Foo].encode(Foo("a", "b", "c")).asInstanceOf[ImmutableRecord] 13 | // record.values shouldBe Vector(new Utf8("a"), new Utf8("c")) 14 | // } 15 | //} 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/encoder/EitherEncoderTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.record.encoder 2 | 3 | import com.sksamuel.avro4s.{AvroSchema, Encoder, ImmutableRecord} 4 | import org.apache.avro.util.Utf8 5 | import org.scalatest.funsuite.AnyFunSuite 6 | import org.scalatest.matchers.should.Matchers 7 | 8 | class EitherEncoderTest extends AnyFunSuite with Matchers { 9 | 10 | test("generate union:T,U for Either[T,U] of primitives") { 11 | case class Test(either: Either[String, Double]) 12 | val schema = AvroSchema[Test] 13 | Encoder[Test].encode(schema).apply(Test(Left("foo"))) shouldBe ImmutableRecord(AvroSchema[Test], Vector(new Utf8("foo"))) 14 | Encoder[Test].encode(schema).apply(Test(Right(234.4D))) shouldBe ImmutableRecord(AvroSchema[Test], Vector(java.lang.Double.valueOf(234.4D))) 15 | } 16 | 17 | test("generate union:T,U for Either[T,U] of case classes") { 18 | case class Goo(s: String) 19 | case class Foo(b: Boolean) 20 | case class Test(either: Either[Goo, Foo]) 21 | val schema = AvroSchema[Test] 22 | Encoder[Test].encode(schema).apply(Test(Left(Goo("zzz")))) shouldBe ImmutableRecord(AvroSchema[Test], Vector(ImmutableRecord(AvroSchema[Goo], Vector(new Utf8("zzz"))))) 23 | Encoder[Test].encode(schema).apply(Test(Right(Foo(true)))) shouldBe ImmutableRecord(AvroSchema[Test], Vector(ImmutableRecord(AvroSchema[Foo], Vector(java.lang.Boolean.valueOf(true))))) 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/encoder/FieldMapperEncoderTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.record.encoder 2 | // 3 | //import com.sksamuel.avro4s.{Encoder, SchemaFor, SnakeCase} 4 | //import org.apache.avro.generic.GenericRecord 5 | //import org.scalatest.funsuite.AnyFunSuite 6 | //import org.scalatest.matchers.should.Matchers 7 | // 8 | //class FieldMapperEncoderTest extends AnyFunSuite with Matchers { 9 | // 10 | // test("adding an in scope FieldMapper should overide the fields in an encoder") { 11 | // implicit val fieldMapper = SnakeCase 12 | // val schema: SchemaFor[NamingTest] = SchemaFor[NamingTest] 13 | // val encoder = Encoder[NamingTest] 14 | // val record = encoder.encode(NamingTest("Foo")).asInstanceOf[GenericRecord] 15 | // record.get("camel_case") 16 | // } 17 | // 18 | //} 19 | // 20 | //case class NamingTest(camelCase: String) -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/encoder/NestedStructEncoderTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.record.encoder 2 | 3 | import com.sksamuel.avro4s.{AvroSchema, Encoder, ImmutableRecord} 4 | import org.apache.avro.util.Utf8 5 | import org.scalatest.funsuite.AnyFunSuite 6 | import org.scalatest.matchers.should.Matchers 7 | 8 | class NestedStructEncoderTest extends AnyFunSuite with Matchers { 9 | 10 | test("encode nested structs") { 11 | 12 | case class Foo(s: String) 13 | case class Fooo(foo: Foo) 14 | case class Foooo(fooo: Fooo) 15 | 16 | Encoder[Foooo].encode(AvroSchema[Foooo]).apply(Foooo(Fooo(Foo("a")))) shouldBe 17 | ImmutableRecord( 18 | AvroSchema[Foooo], 19 | Vector( 20 | ImmutableRecord( 21 | AvroSchema[Fooo], 22 | Vector( 23 | ImmutableRecord( 24 | AvroSchema[Foo], 25 | Vector(new Utf8("a")))) 26 | ) 27 | ) 28 | ) 29 | } 30 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/encoder/ReorderFieldsEncoderTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.record.encoder 2 | 3 | import com.sksamuel.avro4s.{Decoder, Encoder, ImmutableRecord, SchemaFor} 4 | import org.apache.avro.Schema 5 | import org.apache.avro.generic.GenericData 6 | import org.apache.avro.util.Utf8 7 | import org.scalatest.matchers.must.Matchers 8 | import org.scalatest.wordspec.AnyWordSpec 9 | 10 | class ReorderFieldsEncoderTest extends AnyWordSpec with Matchers { 11 | 12 | val schema = new Schema.Parser().parse( 13 | """ 14 | |{ 15 | | "type" : "record", 16 | | "name" : "TestClass", 17 | | "namespace" : "com.sksamuel.avro4s.record.encoder.ReorderFieldsEncoderTest", 18 | | "fields" : [ { 19 | | "name" : "second", 20 | | "type" : "int" 21 | | }, { 22 | | "name" : "first", 23 | | "type" : "string" 24 | | } ] 25 | |}""".stripMargin) 26 | 27 | "RecordEncoder" should { 28 | "respect schema field order" in { 29 | Encoder[TestClass] 30 | .encode(schema) 31 | .apply(TestClass("hello", 42)) mustBe ImmutableRecord(schema, Seq(Integer.valueOf(42), new Utf8("hello"))) 32 | } 33 | } 34 | } 35 | 36 | case class TestClass(first: String, second: Int) -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/encoder/StructEncoderTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.record.encoder 2 | // 3 | //import com.sksamuel.avro4s.{AvroSchema, Encoder, ImmutableRecord} 4 | //import org.apache.avro.util.Utf8 5 | //import org.scalatest.matchers.should.Matchers 6 | //import org.scalatest.wordspec.AnyWordSpec 7 | // 8 | //case class County(name: String, towns: Seq[Town], ceremonial: Boolean, lat: Double, long: Double) 9 | //case class Town(name: String, population: Int) 10 | // 11 | //class StructEncoderTest extends AnyWordSpec with Matchers { 12 | // 13 | // import scala.collection.JavaConverters._ 14 | // 15 | // "RecordEncoder" should { 16 | // "encode structs" in { 17 | // val countySchema = AvroSchema[County] 18 | // val townSchema = AvroSchema[Town] 19 | // val count = County("Bucks", Seq(Town("Hardwick", 123), Town("Weedon", 225)), true, 12.34, 0.123) 20 | // val result = Encoder[County].encode(count) 21 | // 22 | // val hardwick = ImmutableRecord(townSchema, Vector(new Utf8("Hardwick"), java.lang.Integer.valueOf(123))) 23 | // val weedon = ImmutableRecord(townSchema, Vector(new Utf8("Weedon"), java.lang.Integer.valueOf(225))) 24 | // result shouldBe ImmutableRecord(countySchema, Vector(new Utf8("Bucks"), List(hardwick, weedon).asJava, java.lang.Boolean.valueOf(true), java.lang.Double.valueOf(12.34), java.lang.Double.valueOf(0.123))) 25 | // } 26 | // } 27 | //} 28 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/record/encoder/ValueTypeEncoderTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.record.encoder 2 | // 3 | //import com.sksamuel.avro4s.{AvroSchema, Encoder, ImmutableRecord} 4 | //import org.apache.avro.util.Utf8 5 | //import org.scalatest.funsuite.AnyFunSuite 6 | //import org.scalatest.matchers.should.Matchers 7 | // 8 | //class ValueTypeEncoderTest extends AnyFunSuite with Matchers { 9 | // 10 | // test("top level value types") { 11 | // val schema = AvroSchema[FooValueType] 12 | // Encoder[FooValueType].encode(FooValueType("hello")) shouldBe new Utf8("hello") 13 | // } 14 | // 15 | // test("support fields that are value types") { 16 | // case class Test(foo: FooValueType) 17 | // val schema = AvroSchema[Test] 18 | // Encoder[Test].encode(Test(FooValueType("hello"))) shouldBe ImmutableRecord(schema, Vector(new Utf8("hello"))) 19 | // } 20 | // 21 | // test("support value types inside Options") { 22 | // case class Test(foo: Option[FooValueType]) 23 | // val schema = AvroSchema[Test] 24 | // val record = Encoder[Test].encode(Test(Some(FooValueType("hello")))) 25 | // record shouldBe ImmutableRecord(schema, Vector(new Utf8("hello"))) 26 | // } 27 | //} 28 | // 29 | //case class FooValueType(s: String) extends AnyVal 30 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/AvroErrorSchemaTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schema 2 | 3 | import com.sksamuel.avro4s.{AvroError, AvroSchema} 4 | import org.scalatest.funsuite.AnyFunSuite 5 | import org.scalatest.matchers.should.Matchers 6 | import org.scalatest.wordspec.AnyWordSpec 7 | 8 | class AvroErrorSchemaTest extends AnyFunSuite with Matchers { 9 | 10 | test("@AvroError should set schema type to Error when used on a case class") { 11 | @AvroError case class Flibble(val a: String) 12 | val schema = AvroSchema[Flibble] 13 | val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/avro_error.json")) 14 | schema.toString(true) shouldBe expected.toString(true) 15 | } 16 | 17 | test("@AvroError should set schema type to Error when used on a field") { 18 | case class VeryCross(@AvroError flibble: Flibble) 19 | case class Flibble(val a: String) 20 | val schema = AvroSchema[VeryCross] 21 | val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/avro_error_field.json")) 22 | schema.toString(true) shouldBe expected.toString(true) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/AvroNoDefaultTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schema 2 | 3 | import com.sksamuel.avro4s.{AvroNoDefault, AvroSchema} 4 | import org.scalatest.funsuite.AnyFunSuite 5 | import org.scalatest.matchers.should.Matchers 6 | 7 | class AvroNoDefaultTest extends AnyFunSuite with Matchers { 8 | test("a field annotated with @AvroNoDefault should ignore a scala default") { 9 | val schema = AvroSchema[NoDefaultTest] 10 | val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/avro_nodefault.json")) 11 | schema.toString(true) shouldBe expected.toString(true) 12 | } 13 | } 14 | 15 | case class NoDefaultTest(@AvroNoDefault a: String = "foowoo") 16 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/AvroSchemaMergeTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schema 2 | 3 | import com.sksamuel.avro4s.avroutils.AvroSchemaMerge 4 | import org.apache.avro.SchemaBuilder 5 | import org.scalatest.matchers.should.Matchers 6 | import org.scalatest.wordspec.AnyWordSpec 7 | 8 | class AvroSchemaMergeTest extends AnyWordSpec with Matchers { 9 | "AvroSchemaMerge" should { 10 | "merge schemas with union type" in { 11 | val schemaOne = SchemaBuilder 12 | .builder("test") 13 | .record("s1") 14 | .fields() 15 | .requiredString("f1") 16 | .nullableLong("f2", 0) 17 | .endRecord() 18 | 19 | val schemaTwo = SchemaBuilder 20 | .builder("test") 21 | .record("s2") 22 | .fields() 23 | .optionalString("f1") 24 | .requiredLong("f2") 25 | .endRecord() 26 | 27 | val expected = SchemaBuilder 28 | .builder("test") 29 | .record("s3") 30 | .fields() 31 | .optionalString("f1") 32 | .nullableLong("f2", 0) 33 | .endRecord() 34 | 35 | AvroSchemaMerge.apply("s3", "test", List(schemaOne, schemaTwo)).toString shouldBe expected.toString 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/DefaultValueRecordTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.schema 2 | // 3 | // 4 | //import com.sksamuel.avro4s.{AvroName, AvroSchema, FromRecord, ToRecord} 5 | //import org.scalatest.matchers.should.Matchers 6 | //import org.scalatest.wordspec.AnyWordSpec 7 | // 8 | //class DefaultValueRecordTest extends AnyWordSpec with Matchers { 9 | // 10 | // "Converting to and from Avro GenericRecord" should { 11 | // 12 | // "use the default where appropriate" in { 13 | // FromRecord[Jude2].from(ToRecord[Jude].to(Jude())) shouldBe Jude2() 14 | // } 15 | // 16 | // } 17 | // 18 | //} 19 | // 20 | //sealed trait Cup 21 | //case object CKola extends Cup 22 | //case class Bobby(hatesVarg: String) extends Cup 23 | // 24 | //case class Catcup(cupcat: Cup = Bobby("hates varg")) 25 | //case class Jude(hatesVarg: Cup = CKola) 26 | // 27 | //@AvroName("Cup") 28 | //sealed trait Cup2 29 | // 30 | //object Cup2 { 31 | // case class Bobby(hatesVarg: String) extends Cup2 32 | //} 33 | // 34 | //case class Jude2(hatesVarg: Cup2 = Cup2.Bobby("hates varg")) -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/MyJavaEnum.java: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schema; 2 | 3 | @org.apache.avro.specific.AvroGenerated 4 | public enum MyJavaEnum { 5 | A, B, C ; 6 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/StringSchemasTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schema 2 | 3 | import com.sksamuel.avro4s.{AvroSchema, Encoder, ImmutableRecord, SchemaFor} 4 | import com.sksamuel.avro4s.examples.UppercasePkg.ClassInUppercasePackage 5 | import com.sksamuel.avro4s.schemas.JavaStringSchemaFor 6 | import org.scalatest.matchers.should.Matchers 7 | import org.scalatest.wordspec.AnyWordSpec 8 | 9 | class StringSchemasTest extends AnyWordSpec with Matchers { 10 | 11 | "SchemaEncoder" should { 12 | "accept strings" in { 13 | case class Test(str: String) 14 | val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/string.json")) 15 | val schema = AvroSchema[Test] 16 | schema.toString(true) shouldBe expected.toString(true) 17 | } 18 | "encode strings as java strings when JavaStringSchemaFor is in scope" in { 19 | case class Foo(s: String) 20 | given SchemaFor[String] = JavaStringSchemaFor 21 | val schema = AvroSchema[Foo] 22 | val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/java_string.json")) 23 | schema.toString(true) shouldBe expected.toString(true) 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/TransientSchemaTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schema 2 | 3 | import com.sksamuel.avro4s.{AvroSchema, AvroTransient} 4 | import org.scalatest.funsuite.AnyFunSuite 5 | import org.scalatest.matchers.should.Matchers 6 | 7 | class TransientSchemaTest extends AnyFunSuite with Matchers { 8 | 9 | test("@AvroTransient fields should be ignored") { 10 | case class TransientFoo(a: String, @AvroTransient b: String, c: String) 11 | val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/transient.json")) 12 | val schema = AvroSchema[TransientFoo] 13 | schema.toString(true) shouldBe expected.toString(true) 14 | } 15 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/UtfSchemaTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schema 2 | 3 | import com.sksamuel.avro4s.{AvroSchema} 4 | import org.apache.avro.util.Utf8 5 | import org.scalatest.funsuite.AnyFunSuite 6 | import org.scalatest.matchers.should.Matchers 7 | 8 | class UtfSchemaTest extends AnyFunSuite with Matchers { 9 | 10 | test("support utf8 fields as strings") { 11 | case class Person(name: Utf8, alias: Utf8, age: Int) 12 | val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/utf8.json")) 13 | val schema = AvroSchema[Person] 14 | schema.toString(true) shouldBe expected.toString(true) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/ValueTypeSchemaTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.schema 2 | // 3 | //import com.sksamuel.avro4s.AvroSchema 4 | //import org.scalatest.matchers.should.Matchers 5 | //import org.scalatest.wordspec.AnyWordSpec 6 | // 7 | //class ValueTypeSchemaTest extends AnyWordSpec with Matchers { 8 | // 9 | // "SchemaEncoder" should { 10 | // "support value class at the top level" in { 11 | // val schema = AvroSchema[ValueClass] 12 | // val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/value_class_top_level.json")) 13 | // schema.toString(true) shouldBe expected.toString(true) 14 | // } 15 | // "support value class as a nested field" in { 16 | // case class Wibble(value: ValueClass) 17 | // val schema = AvroSchema[Wibble] 18 | // val expected = new org.apache.avro.Schema.Parser().parse(getClass.getResourceAsStream("/value_class_nested.json")) 19 | // schema.toString(true) shouldBe expected.toString(true) 20 | // } 21 | // } 22 | //} 23 | // 24 | //case class ValueClass(str: String) extends AnyVal 25 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/Wine.java: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schema; 2 | 3 | public enum Wine { 4 | Malbec, Shiraz, CabSav, Merlot 5 | } 6 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/WineWithAnnotations.java: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.schema; 2 | 3 | import com.sksamuel.avro4s.AvroJavaEnumDefault; 4 | import com.sksamuel.avro4s.AvroJavaName; 5 | import com.sksamuel.avro4s.AvroJavaNamespace; 6 | import com.sksamuel.avro4s.AvroJavaProp; 7 | 8 | @AvroJavaName("Wine") 9 | @AvroJavaNamespace("test") 10 | @AvroJavaProp(key = "hello", value = "world") 11 | public enum WineWithAnnotations { 12 | Malbec, 13 | Shiraz, 14 | @AvroJavaEnumDefault CabSav, 15 | Merlot 16 | } 17 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/schema/package.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s 2 | 3 | package object schema { 4 | case class Sigma(a: String) 5 | } 6 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/streams/input/BasicInputStreamTest.scala: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.streams.input 2 | 3 | import com.sksamuel.avro4s._ 4 | 5 | import scala.util.Failure 6 | 7 | class BasicInputStreamTest extends InputStreamTest { 8 | 9 | case class BooleanTest(z: Boolean) 10 | case class StringTest(z: String) 11 | case class FloatTest(z: Float) 12 | case class DoubleTest(z: Double) 13 | case class IntTest(z: Int) 14 | case class LongTest(z: Long) 15 | 16 | test("read write out booleans") { 17 | writeRead(BooleanTest(true)) 18 | } 19 | 20 | test("read and skip over corrupted data") { 21 | val items = tryReadData[StringTest](writeData(FloatTest(3.4F)).toByteArray).toSeq 22 | items.size shouldBe 1 23 | items.head shouldBe a[Failure[_]] 24 | } 25 | 26 | test("read write out strings") { 27 | writeRead(StringTest("Hello world")) 28 | } 29 | 30 | test("read write out longs") { 31 | writeRead(LongTest(65653L)) 32 | } 33 | 34 | test("read write out ints") { 35 | writeRead(IntTest(44)) 36 | } 37 | 38 | test("read write out doubles") { 39 | writeRead(DoubleTest(3.235)) 40 | } 41 | 42 | test("read write out floats") { 43 | writeRead(FloatTest(3.4F)) 44 | } 45 | } -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/streams/input/BigDecimalInputStreamTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.streams.input 2 | // 3 | //class BigDecimalInputStreamTest extends InputStreamTest { 4 | // 5 | // case class BigDecimalTest(z: BigDecimal) 6 | // case class BigDecimalOptionTest(z: Option[BigDecimal]) 7 | // case class BigDecimalSeqs(z: Seq[BigDecimal]) 8 | // case class BigDecimalDefault(z: BigDecimal = BigDecimal(1234.56)) 9 | // 10 | // test("read write big decimal") { 11 | // writeRead(BigDecimalTest(4.12)) 12 | // } 13 | // 14 | // test("read write big decimal with default value") { 15 | // writeRead(BigDecimalDefault(), BigDecimalDefault(1234.56)) 16 | // } 17 | // 18 | // test("read write seq of big decimal") { 19 | // writeRead(BigDecimalSeqs(Seq(56.3, 179.2))) 20 | // } 21 | // 22 | // test("read write option of big decimal") { 23 | // writeRead(BigDecimalOptionTest(Some(56.3))) 24 | // writeRead(BigDecimalOptionTest(None)) 25 | // } 26 | //} -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/streams/input/EitherInputStreamTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.streams.input 2 | // 3 | //import java.util.UUID 4 | // 5 | //class EitherInputStreamTest extends InputStreamTest { 6 | // 7 | // test("read either of uuids") { 8 | // case class Test(z: Either[Double, UUID]) 9 | // writeRead(Test(Right(UUID.randomUUID()))) 10 | // } 11 | //} -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/streams/input/EnumInputStreamTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.streams.input 2 | // 3 | //import com.sksamuel.avro4s.schema.{Colours, Wine} 4 | //import org.scalatest.funsuite.AnyFunSuite 5 | //import org.scalatest.matchers.should.Matchers 6 | // 7 | //class EnumInputStreamTest extends AnyFunSuite with Matchers with InputStreamTest { 8 | // 9 | // case class JavaEnumTest(z: Wine) 10 | // case class OptionalJavaEnumTest(z: Option[Wine]) 11 | // case class ScalaEnumTest(z: Colours.Value) 12 | // case class OptionalScalaEnumTest(z: Option[Colours.Value]) 13 | // 14 | // test("java enum") { 15 | // writeRead(JavaEnumTest(Wine.Malbec)) 16 | // } 17 | // 18 | // test("optional java enum") { 19 | // writeRead(OptionalJavaEnumTest(Some(Wine.Malbec))) 20 | // writeRead(OptionalJavaEnumTest(None)) 21 | // } 22 | // 23 | // test("scala enum") { 24 | // writeRead(ScalaEnumTest(Colours.Green)) 25 | // } 26 | // 27 | // test("optional scala enum") { 28 | // writeRead(OptionalScalaEnumTest(Some(Colours.Green))) 29 | // writeRead(OptionalScalaEnumTest(None)) 30 | // } 31 | //} 32 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/streams/output/Style.java: -------------------------------------------------------------------------------- 1 | package com.sksamuel.avro4s.streams.output; 2 | 3 | public enum Style { 4 | Classical, 5 | Modern 6 | } 7 | -------------------------------------------------------------------------------- /avro4s-core/src/test/scala/com/sksamuel/avro4s/streams/output/ValueTypeOutputStreamTest.scala: -------------------------------------------------------------------------------- 1 | //package com.sksamuel.avro4s.streams.output 2 | // 3 | //import com.sksamuel.avro4s.record.encoder.FooValueType 4 | //import org.apache.avro.util.Utf8 5 | // 6 | //class ValueTypeOutputStreamTest extends OutputStreamTest { 7 | // 8 | // test("value type") { 9 | // case class Test(foo: FooValueType) 10 | // writeRead(Test(FooValueType("abc"))) { record => 11 | // record.get("foo") shouldBe new Utf8("abc") 12 | // } 13 | // } 14 | // 15 | // test("value types inside Options") { 16 | // case class Test(foo: Option[FooValueType]) 17 | // writeRead(Test(Some(FooValueType("abc")))) { record => 18 | // record.get("foo") shouldBe new Utf8("abc") 19 | // } 20 | // writeRead(Test(None)) { record => 21 | // record.get("foo") shouldBe null 22 | // } 23 | // } 24 | //} 25 | -------------------------------------------------------------------------------- /benchmarks.txt: -------------------------------------------------------------------------------- 1 | i9 32mb scala3 avro4s 5 2 | 3 | [info] Benchmark Mode Cnt Score Error Units 4 | [info] Decoding.avroSpecificRecord thrpt 10 5006159.788 ± 443579.220 ops/s 5 | [info] Encoding.avro4sGenerated thrpt 10 275992.310 ± 9880.629 ops/s 6 | [info] Encoding.avroSpecificRecord thrpt 10 6534285.366 ± 39962.503 ops/s 7 | 8 | scala 2.13 avro4s 4.0.9 9 | 10 | [info] Benchmark Mode Cnt Score Error Units 11 | [info] Decoding.avro4sGenerated thrpt 10 1638737.327 ± 70792.983 ops/s 12 | [info] Decoding.avro4sHandrolled thrpt 10 1701543.320 ± 21672.076 ops/s 13 | [info] Decoding.avroSpecificRecord thrpt 10 5211411.669 ± 34334.890 ops/s 14 | [info] Encoding.avro4sGenerated thrpt 10 4403288.685 ± 51304.956 ops/s 15 | [info] Encoding.avro4sHandrolled thrpt 10 4975463.867 ± 19560.720 ops/s 16 | [info] Encoding.avroSpecificRecord thrpt 10 6606364.433 ± 29425.717 ops/s 17 | -------------------------------------------------------------------------------- /benchmarks/src/main/scala/benchmarks/BenchmarkHelpers.scala: -------------------------------------------------------------------------------- 1 | package benchmarks 2 | 3 | import java.time.Instant 4 | 5 | trait BenchmarkHelpers { 6 | 7 | val now: Instant = Instant.now 8 | var counter = 0L 9 | 10 | def t: Instant = { 11 | counter += 1 12 | now.minusSeconds(counter) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /benchmarks/src/main/scala/benchmarks/CommonParams.scala: -------------------------------------------------------------------------------- 1 | package benchmarks 2 | 3 | import java.io.InputStream 4 | import java.util 5 | import java.util.concurrent.TimeUnit 6 | 7 | import org.openjdk.jmh.annotations._ 8 | 9 | @State(Scope.Thread) 10 | @Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) 11 | @Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) 12 | @Fork(value = 1, jvmArgs = Array( 13 | "-server", 14 | "-Xms2g", 15 | "-Xmx2g", 16 | "-XX:NewSize=1g", 17 | "-XX:MaxNewSize=1g", 18 | "-XX:InitialCodeCacheSize=512m", 19 | "-XX:ReservedCodeCacheSize=512m", 20 | "-XX:+UseParallelGC", 21 | "-XX:-UseAdaptiveSizePolicy", 22 | "-XX:MaxInlineLevel=18", 23 | "-XX:-UseBiasedLocking", 24 | "-XX:+AlwaysPreTouch", 25 | "-XX:+UseNUMA", 26 | "-XX:-UseAdaptiveNUMAChunkSizing" 27 | )) 28 | @BenchmarkMode(Array(Mode.Throughput)) 29 | @OutputTimeUnit(TimeUnit.SECONDS) 30 | abstract class CommonParams { 31 | def bytes(in: InputStream): Array[Byte] = try { 32 | val step = 8192 33 | var buf = new Array[Byte](step) 34 | var pos, n = 0 35 | while ({ 36 | if (pos + step > buf.length) buf = util.Arrays.copyOf(buf, buf.length << 1) 37 | n = in.read(buf, pos, step) 38 | n != -1 39 | }) pos += n 40 | if (pos != buf.length) buf = util.Arrays.copyOf(buf, pos) 41 | buf 42 | } finally in.close() 43 | } -------------------------------------------------------------------------------- /benchmarks/src/main/scala/benchmarks/record/Attributes.scala: -------------------------------------------------------------------------------- 1 | package benchmarks.record 2 | 3 | import java.time.Instant 4 | 5 | sealed trait IntAttributeValue { 6 | def timestamp: Instant 7 | } 8 | 9 | object IntAttributeValue { 10 | final case class Empty(timestamp: Instant) extends IntAttributeValue 11 | 12 | final case class Invalid(value: Option[String], timestamp: Instant, errors: Set[String]) extends IntAttributeValue 13 | 14 | final case class Valid(value: Int, timestamp: Instant) extends IntAttributeValue 15 | } 16 | 17 | sealed trait AttributeValue[+A] { 18 | def timestamp: Instant 19 | } 20 | 21 | object AttributeValue { 22 | 23 | final case class Empty(timestamp: Instant) extends AttributeValue[Nothing] 24 | 25 | final case class Invalid(value: Option[String], timestamp: Instant, errors: Set[String]) 26 | extends AttributeValue[Nothing] 27 | 28 | final case class Valid[A](value: A, timestamp: Instant) extends AttributeValue[A] 29 | 30 | } 31 | -------------------------------------------------------------------------------- /benchmarks/src/main/scala/benchmarks/record/Records.scala: -------------------------------------------------------------------------------- 1 | package benchmarks.record 2 | 3 | case class RecordWithSimpleField(attribute: IntAttributeValue.Valid) 4 | 5 | case class RecordWithUnionField(attribute: IntAttributeValue) 6 | 7 | case class RecordWithTypeParamField(attribute: AttributeValue.Valid[Int]) 8 | 9 | case class RecordWithUnionAndTypeField(attribute: AttributeValue[Int]) 10 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sksamuel/avro4s/e9c5772edf639b3178ed0fd352b89a17a4c5d835/logo.png -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.10.6 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | resolvers += Classpaths.sbtPluginReleases 2 | 3 | addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1") 4 | 5 | addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2") 6 | 7 | addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7") -------------------------------------------------------------------------------- /run_benchmarks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | sbt benchmarks/jmh:run --------------------------------------------------------------------------------