diff --git a/api/avro4k-core.api b/api/avro4k-core.api new file mode 100644 index 00000000..bfd0736c --- /dev/null +++ b/api/avro4k-core.api @@ -0,0 +1,444 @@ +public abstract class com/github/avrokotlin/avro4k/Avro { + public static final field Default Lcom/github/avrokotlin/avro4k/Avro$Default; + public synthetic fun (Lcom/github/avrokotlin/avro4k/AvroConfiguration;Lkotlinx/serialization/modules/SerializersModule;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun decodeFromByteArray (Lorg/apache/avro/Schema;Lkotlinx/serialization/DeserializationStrategy;[B)Ljava/lang/Object; + public final fun decodeFromGenericData (Lorg/apache/avro/Schema;Lkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object; + public final fun decodeFromStream (Lorg/apache/avro/Schema;Lkotlinx/serialization/DeserializationStrategy;Ljava/io/InputStream;)Ljava/lang/Object; + public final fun encodeToByteArray (Lorg/apache/avro/Schema;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)[B + public final fun encodeToGenericData (Lorg/apache/avro/Schema;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ljava/lang/Object; + public final fun encodeToStream (Lorg/apache/avro/Schema;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;Ljava/io/OutputStream;)V + public final fun getConfiguration ()Lcom/github/avrokotlin/avro4k/AvroConfiguration; + public final fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; + public final fun schema (Lkotlinx/serialization/descriptors/SerialDescriptor;)Lorg/apache/avro/Schema; +} + +public final class com/github/avrokotlin/avro4k/Avro$Default : com/github/avrokotlin/avro4k/Avro { +} + +public abstract interface annotation class com/github/avrokotlin/avro4k/AvroAlias : java/lang/annotation/Annotation { + public abstract fun value ()[Ljava/lang/String; +} + +public synthetic class com/github/avrokotlin/avro4k/AvroAlias$Impl : com/github/avrokotlin/avro4k/AvroAlias { + public fun ([Ljava/lang/String;)V + public final synthetic fun value ()[Ljava/lang/String; +} + +public final class com/github/avrokotlin/avro4k/AvroBuilder { + public final fun build ()Lcom/github/avrokotlin/avro4k/AvroConfiguration; + public final fun getEncodedAs ()Lcom/github/avrokotlin/avro4k/EncodedAs; + public final fun getFieldNamingStrategy ()Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy; + public final fun getImplicitNulls ()Z + public final fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; + public final fun setEncodedAs (Lcom/github/avrokotlin/avro4k/EncodedAs;)V + public final fun setFieldNamingStrategy (Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy;)V + public final fun setImplicitNulls (Z)V + public final fun setSerializersModule (Lkotlinx/serialization/modules/SerializersModule;)V +} + +public final class com/github/avrokotlin/avro4k/AvroConfiguration { + public fun ()V + public fun (Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy;ZLcom/github/avrokotlin/avro4k/EncodedAs;)V + public synthetic fun (Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy;ZLcom/github/avrokotlin/avro4k/EncodedAs;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy; + public final fun component2 ()Z + public final fun component3 ()Lcom/github/avrokotlin/avro4k/EncodedAs; + public final fun copy (Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy;ZLcom/github/avrokotlin/avro4k/EncodedAs;)Lcom/github/avrokotlin/avro4k/AvroConfiguration; + public static synthetic fun copy$default (Lcom/github/avrokotlin/avro4k/AvroConfiguration;Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy;ZLcom/github/avrokotlin/avro4k/EncodedAs;ILjava/lang/Object;)Lcom/github/avrokotlin/avro4k/AvroConfiguration; + public fun equals (Ljava/lang/Object;)Z + public final fun getFieldNamingStrategy ()Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy; + public final fun getImplicitNulls ()Z + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public abstract interface annotation class com/github/avrokotlin/avro4k/AvroDecimal : java/lang/annotation/Annotation { + public abstract fun precision ()I + public abstract fun scale ()I +} + +public synthetic class com/github/avrokotlin/avro4k/AvroDecimal$Impl : com/github/avrokotlin/avro4k/AvroDecimal { + public fun (II)V + public synthetic fun (IIILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final synthetic fun precision ()I + public final synthetic fun scale ()I +} + +public abstract interface annotation class com/github/avrokotlin/avro4k/AvroDefault : java/lang/annotation/Annotation { + public abstract fun value ()Ljava/lang/String; +} + +public synthetic class com/github/avrokotlin/avro4k/AvroDefault$Impl : com/github/avrokotlin/avro4k/AvroDefault { + public fun (Ljava/lang/String;)V + public final synthetic fun value ()Ljava/lang/String; +} + +public abstract interface annotation class com/github/avrokotlin/avro4k/AvroDoc : java/lang/annotation/Annotation { + public abstract fun value ()Ljava/lang/String; +} + +public synthetic class com/github/avrokotlin/avro4k/AvroDoc$Impl : com/github/avrokotlin/avro4k/AvroDoc { + public fun (Ljava/lang/String;)V + public final synthetic fun value ()Ljava/lang/String; +} + +public abstract interface annotation class com/github/avrokotlin/avro4k/AvroEnumDefault : java/lang/annotation/Annotation { +} + +public synthetic class com/github/avrokotlin/avro4k/AvroEnumDefault$Impl : com/github/avrokotlin/avro4k/AvroEnumDefault { + public fun ()V +} + +public abstract interface annotation class com/github/avrokotlin/avro4k/AvroFixed : java/lang/annotation/Annotation { + public abstract fun size ()I +} + +public synthetic class com/github/avrokotlin/avro4k/AvroFixed$Impl : com/github/avrokotlin/avro4k/AvroFixed { + public fun (I)V + public final synthetic fun size ()I +} + +public final class com/github/avrokotlin/avro4k/AvroKt { + public static final fun Avro (Lcom/github/avrokotlin/avro4k/Avro;Lkotlin/jvm/functions/Function1;)Lcom/github/avrokotlin/avro4k/Avro; + public static synthetic fun Avro$default (Lcom/github/avrokotlin/avro4k/Avro;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/github/avrokotlin/avro4k/Avro; + public static final fun schema (Lcom/github/avrokotlin/avro4k/Avro;Lkotlinx/serialization/KSerializer;)Lorg/apache/avro/Schema; +} + +public synthetic class com/github/avrokotlin/avro4k/AvroLogicalType$Impl : com/github/avrokotlin/avro4k/AvroLogicalType { + public fun (Lkotlin/reflect/KClass;)V + public final synthetic fun value ()Ljava/lang/Class; +} + +public abstract interface annotation class com/github/avrokotlin/avro4k/AvroNamespaceOverride : java/lang/annotation/Annotation { + public abstract fun value ()Ljava/lang/String; +} + +public synthetic class com/github/avrokotlin/avro4k/AvroNamespaceOverride$Impl : com/github/avrokotlin/avro4k/AvroNamespaceOverride { + public fun (Ljava/lang/String;)V + public final synthetic fun value ()Ljava/lang/String; +} + +public final class com/github/avrokotlin/avro4k/AvroObjectContainerFileBuilder { + public fun (Lorg/apache/avro/file/DataFileWriter;)V + public final fun codec (Lorg/apache/avro/file/CodecFactory;)V + public final fun metadata (Ljava/lang/String;J)V + public final fun metadata (Ljava/lang/String;Ljava/lang/String;)V + public final fun metadata (Ljava/lang/String;[B)V +} + +public final class com/github/avrokotlin/avro4k/AvroObjectContainerFileMetadataDumper { + public fun (Lorg/apache/avro/file/DataFileStream;)V + public final fun metadata (Ljava/lang/String;)Lcom/github/avrokotlin/avro4k/AvroObjectContainerFileMetadataDumper$MetadataAccessor; +} + +public final class com/github/avrokotlin/avro4k/AvroObjectContainerFileMetadataDumper$MetadataAccessor { + public fun (Lcom/github/avrokotlin/avro4k/AvroObjectContainerFileMetadataDumper;[B)V + public final fun asBytes ()[B + public final fun asLong ()J + public final fun asString ()Ljava/lang/String; +} + +public abstract interface annotation class com/github/avrokotlin/avro4k/AvroProp : java/lang/annotation/Annotation { + public abstract fun key ()Ljava/lang/String; + public abstract fun value ()Ljava/lang/String; +} + +public abstract interface annotation class com/github/avrokotlin/avro4k/AvroProp$Container : java/lang/annotation/Annotation { + public abstract fun value ()[Lcom/github/avrokotlin/avro4k/AvroProp; +} + +public synthetic class com/github/avrokotlin/avro4k/AvroProp$Impl : com/github/avrokotlin/avro4k/AvroProp { + public fun (Ljava/lang/String;Ljava/lang/String;)V + public final synthetic fun key ()Ljava/lang/String; + public final synthetic fun value ()Ljava/lang/String; +} + +public synthetic class com/github/avrokotlin/avro4k/AvroSchema$Impl : com/github/avrokotlin/avro4k/AvroSchema { + public fun (Lkotlin/reflect/KClass;)V + public final synthetic fun value ()Ljava/lang/Class; +} + +public final class com/github/avrokotlin/avro4k/AvroSingleObjectKt { + public static final fun decodeFromByteArray (Lcom/github/avrokotlin/avro4k/AvroSingleObject;Lkotlinx/serialization/DeserializationStrategy;[B)Ljava/lang/Object; + public static final fun encodeToByteArray (Lcom/github/avrokotlin/avro4k/AvroSingleObject;Lorg/apache/avro/Schema;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)[B +} + +public abstract interface class com/github/avrokotlin/avro4k/decoder/AvroDecoder : kotlinx/serialization/encoding/Decoder { + public abstract fun decodeValue ()Ljava/lang/Object; + public abstract fun getCurrentWriterSchema ()Lorg/apache/avro/Schema; +} + +public final class com/github/avrokotlin/avro4k/decoder/AvroDecoder$DefaultImpls { + public static fun decodeSerializableValue (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object; +} + +public abstract interface class com/github/avrokotlin/avro4k/encoder/AvroEncoder : kotlinx/serialization/encoding/Encoder { + public abstract fun getCurrentWriterSchema ()Lorg/apache/avro/Schema; +} + +public final class com/github/avrokotlin/avro4k/encoder/AvroEncoder$DefaultImpls { + public static fun beginCollection (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/CompositeEncoder; + public static fun encodeSerializableValue (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V +} + +public abstract class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher { + public fun toString ()Ljava/lang/String; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$FirstArray : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$FirstArray; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$FirstMap : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$FirstMap; +} + +public abstract class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher { +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Enum : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named { + public fun (Ljava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;)Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Enum; + public static synthetic fun copy$default (Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Enum;Ljava/lang/String;ILjava/lang/Object;)Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Enum; + public fun equals (Ljava/lang/Object;)Z + public final fun getFullName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$FirstEnum : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$FirstEnum; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$FirstFixed : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$FirstFixed; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Fixed : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named { + public fun (Ljava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;)Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Fixed; + public static synthetic fun copy$default (Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Fixed;Ljava/lang/String;ILjava/lang/Object;)Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Fixed; + public fun equals (Ljava/lang/Object;)Z + public final fun getFullName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Record : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named { + public fun (Ljava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;)Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Record; + public static synthetic fun copy$default (Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Record;Ljava/lang/String;ILjava/lang/Object;)Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Named$Record; + public fun equals (Ljava/lang/Object;)Z + public final fun getFullName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public abstract class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher { +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$BOOLEAN : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$BOOLEAN; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$BYTES : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$BYTES; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$DOUBLE : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$DOUBLE; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$FLOAT : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$FLOAT; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$INT : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$INT; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$LONG : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$LONG; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$NULL : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$NULL; +} + +public final class com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$STRING : com/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/encoder/SchemaTypeMatcher$Scalar$STRING; +} + +public abstract interface class com/github/avrokotlin/avro4k/schema/FieldNamingStrategy { + public static final field Builtins Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy$Builtins; + public abstract fun resolve (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Ljava/lang/String; +} + +public final class com/github/avrokotlin/avro4k/schema/FieldNamingStrategy$Builtins { +} + +public final class com/github/avrokotlin/avro4k/schema/FieldNamingStrategy$Builtins$NoOp : com/github/avrokotlin/avro4k/schema/FieldNamingStrategy { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy$Builtins$NoOp; + public fun resolve (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Ljava/lang/String; +} + +public final class com/github/avrokotlin/avro4k/schema/FieldNamingStrategy$Builtins$SnakeCase : com/github/avrokotlin/avro4k/schema/FieldNamingStrategy { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/schema/FieldNamingStrategy$Builtins$SnakeCase; + public fun resolve (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Ljava/lang/String; +} + +public abstract class com/github/avrokotlin/avro4k/serializer/AvroSerializer : kotlinx/serialization/KSerializer { + public fun ()V + public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public abstract fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public abstract fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V +} + +public abstract class com/github/avrokotlin/avro4k/serializer/AvroTimeSerializer : com/github/avrokotlin/avro4k/serializer/AvroSerializer, com/github/avrokotlin/avro4k/AvroLogicalTypeSupplier { + public fun (Lkotlin/reflect/KClass;Lkotlinx/serialization/descriptors/PrimitiveKind;)V + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; +} + +public final class com/github/avrokotlin/avro4k/serializer/BigDecimalAsStringSerializer : com/github/avrokotlin/avro4k/serializer/AvroSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/BigDecimalAsStringSerializer; + public synthetic fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/math/BigDecimal; + public synthetic fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/math/BigDecimal; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public synthetic fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/math/BigDecimal;)V + public synthetic fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/math/BigDecimal;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/BigDecimalSerializer : com/github/avrokotlin/avro4k/serializer/AvroSerializer, com/github/avrokotlin/avro4k/AvroLogicalTypeSupplier { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/BigDecimalSerializer; + public synthetic fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/math/BigDecimal; + public synthetic fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/math/BigDecimal; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun getLogicalType (Ljava/util/List;)Lorg/apache/avro/LogicalType; + public synthetic fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/math/BigDecimal;)V + public synthetic fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/math/BigDecimal;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/BigIntegerSerializer : com/github/avrokotlin/avro4k/serializer/AvroSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/BigIntegerSerializer; + public synthetic fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/math/BigInteger; + public synthetic fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/math/BigInteger; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public synthetic fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/math/BigInteger;)V + public synthetic fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/math/BigInteger;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/InstantSerializer : com/github/avrokotlin/avro4k/serializer/AvroTimeSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/InstantSerializer; + public synthetic fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/time/Instant; + public synthetic fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/time/Instant; + public fun getLogicalType (Ljava/util/List;)Lorg/apache/avro/LogicalType; + public synthetic fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/time/Instant;)V + public synthetic fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/time/Instant;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/InstantToMicroSerializer : com/github/avrokotlin/avro4k/serializer/AvroTimeSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/InstantToMicroSerializer; + public synthetic fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/time/Instant; + public synthetic fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/time/Instant; + public fun getLogicalType (Ljava/util/List;)Lorg/apache/avro/LogicalType; + public synthetic fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/time/Instant;)V + public synthetic fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/time/Instant;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/LocalDateSerializer : com/github/avrokotlin/avro4k/serializer/AvroTimeSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/LocalDateSerializer; + public synthetic fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/time/LocalDate; + public synthetic fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/time/LocalDate; + public fun getLogicalType (Ljava/util/List;)Lorg/apache/avro/LogicalType; + public synthetic fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/time/LocalDate;)V + public synthetic fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/time/LocalDate;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/LocalDateTimeSerializer : com/github/avrokotlin/avro4k/serializer/AvroTimeSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/LocalDateTimeSerializer; + public synthetic fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/time/LocalDateTime; + public synthetic fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/time/LocalDateTime; + public fun getLogicalType (Ljava/util/List;)Lorg/apache/avro/LogicalType; + public synthetic fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/time/LocalDateTime;)V + public synthetic fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/time/LocalDateTime;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/LocalTimeSerializer : com/github/avrokotlin/avro4k/serializer/AvroTimeSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/LocalTimeSerializer; + public synthetic fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/time/LocalTime; + public synthetic fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/time/LocalTime; + public fun getLogicalType (Ljava/util/List;)Lorg/apache/avro/LogicalType; + public synthetic fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/time/LocalTime;)V + public synthetic fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/time/LocalTime;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/TimestampSerializer : com/github/avrokotlin/avro4k/serializer/AvroTimeSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/TimestampSerializer; + public synthetic fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/lang/Object; + public fun deserializeAvro (Lcom/github/avrokotlin/avro4k/decoder/AvroDecoder;)Ljava/sql/Timestamp; + public synthetic fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserializeGeneric (Lkotlinx/serialization/encoding/Decoder;)Ljava/sql/Timestamp; + public fun getLogicalType (Ljava/util/List;)Lorg/apache/avro/LogicalType; + public synthetic fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/lang/Object;)V + public fun serializeAvro (Lcom/github/avrokotlin/avro4k/encoder/AvroEncoder;Ljava/sql/Timestamp;)V + public synthetic fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serializeGeneric (Lkotlinx/serialization/encoding/Encoder;Ljava/sql/Timestamp;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/URLSerializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/URLSerializer; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/net/URL; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/net/URL;)V +} + +public final class com/github/avrokotlin/avro4k/serializer/UUIDSerializer : com/github/avrokotlin/avro4k/AvroLogicalTypeSupplier, kotlinx/serialization/KSerializer { + public static final field INSTANCE Lcom/github/avrokotlin/avro4k/serializer/UUIDSerializer; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/util/UUID; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun getLogicalType (Ljava/util/List;)Lorg/apache/avro/LogicalType; + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/util/UUID;)V +} + diff --git a/build.gradle.kts b/build.gradle.kts index 0fb5dab1..1b75d34d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { @@ -22,6 +23,7 @@ plugins { alias(libs.plugins.github.versions) alias(libs.plugins.nexus.publish) alias(libs.plugins.spotless) + id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.14.0" } tasks { @@ -42,11 +44,25 @@ dependencies { testImplementation(libs.kotest.property) } +kotlin { + explicitApi = ExplicitApiMode.Strict +} + +apiValidation { + nonPublicMarkers.add("kotlinx.serialization.ExperimentalSerializationApi") +} + tasks.withType().configureEach { kotlinOptions.jvmTarget = "1.8" kotlinOptions.apiVersion = "1.6" kotlinOptions.languageVersion = "1.6" - kotlinOptions.freeCompilerArgs += listOf("-opt-in=kotlinx.serialization.ExperimentalSerializationApi", "-opt-in=kotlin.RequiresOptIn", "-Xcontext-receivers") + kotlinOptions.freeCompilerArgs += + listOf( + "-Xexplicit-api=strict", + "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", + "-opt-in=kotlin.RequiresOptIn", + "-Xcontext-receivers" + ) } java { sourceCompatibility = JavaVersion.VERSION_1_8 diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/Avro.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/Avro.kt index 0ce6301d..ca6597fd 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/Avro.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/Avro.kt @@ -40,16 +40,16 @@ import java.util.concurrent.ConcurrentHashMap /** * The goal of this class is to serialize and deserialize in avro binary format, not in GenericRecords. */ -sealed class Avro( - val configuration: AvroConfiguration, - val serializersModule: SerializersModule, +public sealed class Avro( + public val configuration: AvroConfiguration, + public val serializersModule: SerializersModule, ) { private val schemaCache: MutableMap = ConcurrentHashMap() internal val recordResolver = RecordResolver(this) internal val unionResolver = UnionResolver() internal val enumResolver = EnumResolver() - companion object Default : Avro( + public companion object Default : Avro( AvroConfiguration(), SerializersModule { contextual(UUIDSerializer) @@ -64,7 +64,7 @@ sealed class Avro( } ) - fun schema(descriptor: SerialDescriptor): Schema { + public fun schema(descriptor: SerialDescriptor): Schema { return schemaCache.getOrPut(descriptor) { lateinit var output: Schema ValueVisitor(this) { output = it }.visitValue(descriptor) @@ -72,7 +72,7 @@ sealed class Avro( } } - fun encodeToStream( + public fun encodeToStream( writerSchema: Schema, serializer: SerializationStrategy, value: T, @@ -89,7 +89,7 @@ sealed class Avro( avroEncoder.flush() } - fun encodeToByteArray( + public fun encodeToByteArray( writerSchema: Schema, serializer: SerializationStrategy, value: T, @@ -99,7 +99,7 @@ sealed class Avro( return outputStream.toByteArray() } - fun encodeToGenericData( + public fun encodeToGenericData( writerSchema: Schema, serializer: SerializationStrategy, value: T, @@ -111,7 +111,7 @@ sealed class Avro( return result } - fun decodeFromStream( + public fun decodeFromStream( writerSchema: Schema, deserializer: DeserializationStrategy, inputStream: InputStream, @@ -125,7 +125,7 @@ sealed class Avro( return decodeFromGenericData(writerSchema, deserializer, genericData) } - fun decodeFromByteArray( + public fun decodeFromByteArray( writerSchema: Schema, deserializer: DeserializationStrategy, bytes: ByteArray, @@ -133,7 +133,7 @@ sealed class Avro( return decodeFromStream(writerSchema, deserializer, ByteArrayInputStream(bytes)) } - fun decodeFromGenericData( + public fun decodeFromGenericData( writerSchema: Schema, deserializer: DeserializationStrategy, value: Any?, @@ -143,7 +143,7 @@ sealed class Avro( } } -fun Avro( +public fun Avro( from: Avro = Avro, builderAction: AvroBuilder.() -> Unit, ): Avro { @@ -152,13 +152,13 @@ fun Avro( return AvroImpl(builder.build(), from.serializersModule.overwriteWith(builder.serializersModule)) } -class AvroBuilder internal constructor(avro: Avro) { - var fieldNamingStrategy: FieldNamingStrategy = avro.configuration.fieldNamingStrategy - var implicitNulls: Boolean = avro.configuration.implicitNulls - var encodedAs: EncodedAs = avro.configuration.encodedAs - var serializersModule: SerializersModule = EmptySerializersModule() +public class AvroBuilder internal constructor(avro: Avro) { + public var fieldNamingStrategy: FieldNamingStrategy = avro.configuration.fieldNamingStrategy + public var implicitNulls: Boolean = avro.configuration.implicitNulls + public var encodedAs: EncodedAs = avro.configuration.encodedAs + public var serializersModule: SerializersModule = EmptySerializersModule() - fun build() = + public fun build(): AvroConfiguration = AvroConfiguration( fieldNamingStrategy = fieldNamingStrategy, implicitNulls = implicitNulls, @@ -171,23 +171,23 @@ private class AvroImpl(configuration: AvroConfiguration, serializersModule: Seri // schema gen extensions -inline fun Avro.schema(): Schema { +public inline fun Avro.schema(): Schema { val serializer = serializersModule.serializer() return schema(serializer.descriptor) } -fun Avro.schema(serializer: KSerializer): Schema { +public fun Avro.schema(serializer: KSerializer): Schema { return schema(serializer.descriptor) } // encoding extensions -inline fun Avro.encodeToByteArray(value: T): ByteArray { +public inline fun Avro.encodeToByteArray(value: T): ByteArray { val serializer = serializersModule.serializer() return encodeToByteArray(schema(serializer), serializer, value) } -inline fun Avro.encodeToByteArray( +public inline fun Avro.encodeToByteArray( writerSchema: Schema, value: T, ): ByteArray { @@ -195,12 +195,12 @@ inline fun Avro.encodeToByteArray( return encodeToByteArray(writerSchema, serializer, value) } -inline fun Avro.encodeToGenericData(value: T): Any? { +public inline fun Avro.encodeToGenericData(value: T): Any? { val serializer = serializersModule.serializer() return encodeToGenericData(schema(serializer), serializer, value) } -inline fun Avro.encodeToGenericData( +public inline fun Avro.encodeToGenericData( writerSchema: Schema, value: T, ): Any? { @@ -208,7 +208,7 @@ inline fun Avro.encodeToGenericData( return encodeToGenericData(writerSchema, serializer, value) } -inline fun Avro.encodeToStream( +public inline fun Avro.encodeToStream( value: T, outputStream: OutputStream, ) { @@ -216,7 +216,7 @@ inline fun Avro.encodeToStream( encodeToStream(schema(serializer), serializer, value, outputStream) } -inline fun Avro.encodeToStream( +public inline fun Avro.encodeToStream( writerSchema: Schema, value: T, outputStream: OutputStream, @@ -227,12 +227,12 @@ inline fun Avro.encodeToStream( // decoding extensions -inline fun Avro.decodeFromStream(inputStream: InputStream): T { +public inline fun Avro.decodeFromStream(inputStream: InputStream): T { val serializer = serializersModule.serializer() return decodeFromStream(schema(serializer.descriptor), serializer, inputStream) } -inline fun Avro.decodeFromStream( +public inline fun Avro.decodeFromStream( writerSchema: Schema, inputStream: InputStream, ): T { @@ -240,12 +240,12 @@ inline fun Avro.decodeFromStream( return decodeFromStream(writerSchema, serializer, inputStream) } -inline fun Avro.decodeFromByteArray(bytes: ByteArray): T { +public inline fun Avro.decodeFromByteArray(bytes: ByteArray): T { val serializer = serializersModule.serializer() return decodeFromByteArray(schema(serializer.descriptor), serializer, bytes) } -inline fun Avro.decodeFromByteArray( +public inline fun Avro.decodeFromByteArray( writerSchema: Schema, bytes: ByteArray, ): T { @@ -253,7 +253,7 @@ inline fun Avro.decodeFromByteArray( return decodeFromByteArray(writerSchema, serializer, bytes) } -inline fun Avro.decodeFromGenericData( +public inline fun Avro.decodeFromGenericData( writerSchema: Schema, value: Any?, ): T { @@ -261,7 +261,7 @@ inline fun Avro.decodeFromGenericData( return decodeFromGenericData(writerSchema, deserializer, value) } -inline fun Avro.decodeFromGenericData(value: GenericContainer?): T? { +public inline fun Avro.decodeFromGenericData(value: GenericContainer?): T? { if (value == null) return null val deserializer = serializersModule.serializer() return decodeFromGenericData(value.schema, deserializer, value) diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/AvroConfiguration.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/AvroConfiguration.kt index 2bd8ff58..efcfad3b 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/AvroConfiguration.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/AvroConfiguration.kt @@ -3,7 +3,7 @@ package com.github.avrokotlin.avro4k import com.github.avrokotlin.avro4k.schema.FieldNamingStrategy import kotlinx.serialization.ExperimentalSerializationApi -data class AvroConfiguration( +public data class AvroConfiguration( /** * The naming strategy to use for records' fields name. * @@ -25,7 +25,7 @@ data class AvroConfiguration( ) @ExperimentalSerializationApi -enum class EncodedAs { +public enum class EncodedAs { BINARY, JSON_COMPACT, JSON_PRETTY, diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/AvroObjectContainerFile.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/AvroObjectContainerFile.kt index 21b192e5..c8ed2074 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/AvroObjectContainerFile.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/AvroObjectContainerFile.kt @@ -21,10 +21,11 @@ import java.io.OutputStream * [spec](https://avro.apache.org/docs/1.11.1/specification/#object-container-files) */ @ExperimentalSerializationApi -class AvroObjectContainerFile( - val avro: Avro = Avro, +public class AvroObjectContainerFile( + @PublishedApi + internal val avro: Avro = Avro, ) { - fun encodeToStream( + public fun encodeToStream( schema: Schema, serializer: SerializationStrategy, values: Sequence, @@ -43,7 +44,7 @@ class AvroObjectContainerFile( // don't close the stream, the caller should do it } - fun decodeFromStream( + public fun decodeFromStream( deserializer: DeserializationStrategy, inputStream: InputStream, metadataDumper: AvroObjectContainerFileMetadataDumper.() -> Unit = {}, @@ -57,7 +58,7 @@ class AvroObjectContainerFile( }.constrainOnce() } -inline fun AvroObjectContainerFile.encodeToStream( +public inline fun AvroObjectContainerFile.encodeToStream( values: Sequence, outputStream: OutputStream, noinline builder: AvroObjectContainerFileBuilder.() -> Unit = {}, @@ -66,7 +67,7 @@ inline fun AvroObjectContainerFile.encodeToStream( encodeToStream(avro.schema(serializer), serializer, values, outputStream, builder) } -inline fun AvroObjectContainerFile.decodeFromStream( +public inline fun AvroObjectContainerFile.decodeFromStream( inputStream: InputStream, noinline metadataDumper: AvroObjectContainerFileMetadataDumper.() -> Unit = {}, ): Sequence { @@ -74,44 +75,44 @@ inline fun AvroObjectContainerFile.decodeFromStream( return decodeFromStream(serializer, inputStream, metadataDumper) } -class AvroObjectContainerFileBuilder(private val fileWriter: DataFileWriter<*>) { - fun metadata( +public class AvroObjectContainerFileBuilder(private val fileWriter: DataFileWriter<*>) { + public fun metadata( key: String, value: ByteArray, ) { fileWriter.setMeta(key, value) } - fun metadata( + public fun metadata( key: String, value: String, ) { fileWriter.setMeta(key, value) } - fun metadata( + public fun metadata( key: String, value: Long, ) { fileWriter.setMeta(key, value) } - fun codec(codec: CodecFactory) { + public fun codec(codec: CodecFactory) { fileWriter.setCodec(codec) } } -class AvroObjectContainerFileMetadataDumper(private val fileStream: DataFileStream<*>) { - fun metadata(key: String): MetadataAccessor? { +public class AvroObjectContainerFileMetadataDumper(private val fileStream: DataFileStream<*>) { + public fun metadata(key: String): MetadataAccessor? { return fileStream.getMeta(key)?.let { MetadataAccessor(it) } } - inner class MetadataAccessor(private val value: ByteArray) { - fun asBytes(): ByteArray = value + public inner class MetadataAccessor(private val value: ByteArray) { + public fun asBytes(): ByteArray = value - fun asString(): String = value.decodeToString() + public fun asString(): String = value.decodeToString() - fun asLong(): Long = asString().toLong() + public fun asLong(): Long = asString().toLong() } } diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/AvroSingleObject.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/AvroSingleObject.kt index ab2c7895..26c527bd 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/AvroSingleObject.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/AvroSingleObject.kt @@ -1,6 +1,7 @@ package com.github.avrokotlin.avro4k import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.serializer @@ -22,13 +23,15 @@ import java.nio.ByteOrder * * @param findSchemaByFingerprint a function to find a schema by its fingerprint, and returns null when not found */ -class AvroSingleObject( +@ExperimentalSerializationApi +public class AvroSingleObject( private val findSchemaByFingerprint: (Long) -> Schema?, - val avro: Avro = Avro, + @PublishedApi + internal val avro: Avro = Avro, ) { private fun Schema.crc64avro(): ByteArray = SchemaNormalization.parsingFingerprint("CRC-64-AVRO", this) - fun encodeToStream( + public fun encodeToStream( writerSchema: Schema, serializer: SerializationStrategy, value: T, @@ -40,7 +43,7 @@ class AvroSingleObject( avro.encodeToStream(writerSchema, serializer, value, outputStream) } - fun decodeFromStream( + public fun decodeFromStream( deserializer: DeserializationStrategy, inputStream: InputStream, ): T { @@ -57,7 +60,7 @@ class AvroSingleObject( private const val MAGIC_BYTE: Int = 0xC3 private const val FORMAT_VERSION: Int = 1 -fun AvroSingleObject.encodeToByteArray( +public fun AvroSingleObject.encodeToByteArray( writerSchema: Schema, serializer: SerializationStrategy, value: T, @@ -66,17 +69,17 @@ fun AvroSingleObject.encodeToByteArray( encodeToStream(writerSchema, serializer, value, this) }.toByteArray() -inline fun AvroSingleObject.encodeToByteArray( +public inline fun AvroSingleObject.encodeToByteArray( writerSchema: Schema, value: T, ): ByteArray = encodeToByteArray(writerSchema, avro.serializersModule.serializer(), value) -inline fun AvroSingleObject.encodeToByteArray(value: T): ByteArray { +public inline fun AvroSingleObject.encodeToByteArray(value: T): ByteArray { val serializer = avro.serializersModule.serializer() return encodeToByteArray(avro.schema(serializer), serializer, value) } -fun AvroSingleObject.decodeFromByteArray( +public fun AvroSingleObject.decodeFromByteArray( deserializer: DeserializationStrategy, bytes: ByteArray, ): T = @@ -84,4 +87,4 @@ fun AvroSingleObject.decodeFromByteArray( decodeFromStream(deserializer, it) } -inline fun AvroSingleObject.decodeFromByteArray(bytes: ByteArray): T = decodeFromByteArray(avro.serializersModule.serializer(), bytes) \ No newline at end of file +public inline fun AvroSingleObject.decodeFromByteArray(bytes: ByteArray): T = decodeFromByteArray(avro.serializersModule.serializer(), bytes) \ No newline at end of file diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/annotations.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/annotations.kt index 08215595..e44dd7d1 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/annotations.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/annotations.kt @@ -18,7 +18,7 @@ import kotlin.reflect.KClass */ @SerialInfo @Target(AnnotationTarget.PROPERTY) -annotation class AvroNamespaceOverride( +public annotation class AvroNamespaceOverride( val value: String, ) @@ -30,7 +30,7 @@ annotation class AvroNamespaceOverride( @SerialInfo @Repeatable @Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) -annotation class AvroProp( +public annotation class AvroProp( val key: String, @Language("JSON") val value: String, ) @@ -42,7 +42,7 @@ annotation class AvroProp( */ @SerialInfo @Target(AnnotationTarget.PROPERTY) -annotation class AvroDecimal( +public annotation class AvroDecimal( val scale: Int = 2, val precision: Int = 8, ) @@ -57,7 +57,7 @@ annotation class AvroDecimal( */ @SerialInfo @Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) -annotation class AvroDoc(val value: String) +public annotation class AvroDoc(val value: String) /** * Adds aliases to a field of a record. It helps to allow having different names for the same field for better compatibility when changing a schema. @@ -68,7 +68,7 @@ annotation class AvroDoc(val value: String) */ @SerialInfo @Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) -annotation class AvroAlias(vararg val value: String) +public annotation class AvroAlias(vararg val value: String) /** * Indicates that the annotated property should be encoded as an Avro fixed type. @@ -76,7 +76,7 @@ annotation class AvroAlias(vararg val value: String) */ @SerialInfo @Target(AnnotationTarget.PROPERTY) -annotation class AvroFixed(val size: Int) +public annotation class AvroFixed(val size: Int) /** * Sets the default avro value for a record's field. @@ -85,7 +85,7 @@ annotation class AvroFixed(val size: Int) */ @SerialInfo @Target(AnnotationTarget.PROPERTY) -annotation class AvroDefault( +public annotation class AvroDefault( @Language("JSON") val value: String, ) @@ -96,31 +96,36 @@ annotation class AvroDefault( */ @SerialInfo @Target(AnnotationTarget.PROPERTY) -annotation class AvroEnumDefault +public annotation class AvroEnumDefault /** * Allows to specify the schema of a property. */ @SerialInfo +@ExperimentalSerializationApi @Target(AnnotationTarget.PROPERTY) -annotation class AvroSchema(val value: KClass) +public annotation class AvroSchema(val value: KClass) -interface AvroSchemaSupplier { - fun getSchema(stack: List): Schema +@ExperimentalSerializationApi +public interface AvroSchemaSupplier { + public fun getSchema(stack: List): Schema } /** * Allows to specify the logical type applied on the generated schema of a property. */ @SerialInfo +@ExperimentalSerializationApi @Target(AnnotationTarget.PROPERTY) -annotation class AvroLogicalType(val value: KClass) +public annotation class AvroLogicalType(val value: KClass) -interface AvroLogicalTypeSupplier { - fun getLogicalType(inlinedStack: List): LogicalType +@ExperimentalSerializationApi +public interface AvroLogicalTypeSupplier { + public fun getLogicalType(inlinedStack: List): LogicalType } -interface AnnotatedLocation { - val descriptor: SerialDescriptor - val elementIndex: Int? +@ExperimentalSerializationApi +public interface AnnotatedLocation { + public val descriptor: SerialDescriptor + public val elementIndex: Int? } \ No newline at end of file diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/decoder/AvroDecoder.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/decoder/AvroDecoder.kt index 3f59ed47..582ac5bc 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/decoder/AvroDecoder.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/decoder/AvroDecoder.kt @@ -1,15 +1,19 @@ package com.github.avrokotlin.avro4k.decoder +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.encoding.Decoder import org.apache.avro.Schema import org.apache.avro.generic.GenericFixed -interface AvroDecoder : Decoder { - val currentWriterSchema: Schema +public interface AvroDecoder : Decoder { + @ExperimentalSerializationApi + public val currentWriterSchema: Schema - fun decodeBytes(): ByteArray + @ExperimentalSerializationApi + public fun decodeBytes(): ByteArray - fun decodeFixed(): GenericFixed + @ExperimentalSerializationApi + public fun decodeFixed(): GenericFixed - fun decodeValue(): Any + public fun decodeValue(): Any } \ No newline at end of file diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/ArrayEncoder.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/ArrayEncoder.kt index 24d8f890..0ed0565b 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/ArrayEncoder.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/ArrayEncoder.kt @@ -1,6 +1,7 @@ package com.github.avrokotlin.avro4k.encoder import com.github.avrokotlin.avro4k.Avro +import com.github.avrokotlin.avro4k.schema.ensureTypeOf import kotlinx.serialization.descriptors.SerialDescriptor import org.apache.avro.Schema import org.apache.avro.generic.GenericArray diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/AvroEncoder.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/AvroEncoder.kt index f69d7464..2caaaf8d 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/AvroEncoder.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/AvroEncoder.kt @@ -1,21 +1,26 @@ package com.github.avrokotlin.avro4k.encoder -import kotlinx.serialization.SerializationException +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.encoding.Encoder import org.apache.avro.Schema import org.apache.avro.generic.GenericFixed import java.nio.ByteBuffer -interface AvroEncoder : Encoder { - val currentWriterSchema: Schema +public interface AvroEncoder : Encoder { + @ExperimentalSerializationApi + public val currentWriterSchema: Schema - fun encodeBytes(value: ByteBuffer) + @ExperimentalSerializationApi + public fun encodeBytes(value: ByteBuffer) - fun encodeBytes(value: ByteArray) + @ExperimentalSerializationApi + public fun encodeBytes(value: ByteArray) - fun encodeFixed(value: ByteArray) + @ExperimentalSerializationApi + public fun encodeFixed(value: ByteArray) - fun encodeFixed(value: GenericFixed) + @ExperimentalSerializationApi + public fun encodeFixed(value: GenericFixed) /** * Helps to encode a value in different ways depending on the type of the writer schema. @@ -23,59 +28,54 @@ interface AvroEncoder : Encoder { * * @param kotlinTypeName represents the kotlin type name of the encoded value for debugging purposes as it's used in exceptions. This is not the written avro type name. */ - fun encodeValueResolved( + @ExperimentalSerializationApi + public fun encodeValueResolved( vararg encoders: Pair Any>, kotlinTypeName: String, ) } -inline fun AvroEncoder.encodeValueResolved(vararg encoders: Pair Any>) { +@ExperimentalSerializationApi +public inline fun AvroEncoder.encodeValueResolved(vararg encoders: Pair Any>) { encodeValueResolved(*encoders, kotlinTypeName = T::class.qualifiedName!!) } -sealed class SchemaTypeMatcher { - sealed class Scalar : SchemaTypeMatcher() { - object BOOLEAN : Scalar() +public sealed class SchemaTypeMatcher { + public sealed class Scalar : SchemaTypeMatcher() { + public object BOOLEAN : Scalar() - object INT : Scalar() + public object INT : Scalar() - object LONG : Scalar() + public object LONG : Scalar() - object FLOAT : Scalar() + public object FLOAT : Scalar() - object DOUBLE : Scalar() + public object DOUBLE : Scalar() - object STRING : Scalar() + public object STRING : Scalar() - object BYTES : Scalar() + public object BYTES : Scalar() - object NULL : Scalar() + public object NULL : Scalar() } - object FirstArray : SchemaTypeMatcher() + public object FirstArray : SchemaTypeMatcher() - object FirstMap : SchemaTypeMatcher() + public object FirstMap : SchemaTypeMatcher() - sealed class Named : SchemaTypeMatcher() { - object FirstFixed : Named() + public sealed class Named : SchemaTypeMatcher() { + public object FirstFixed : Named() - object FirstEnum : Named() + public object FirstEnum : Named() - data class Fixed(val fullName: String) : Named() + public data class Fixed(val fullName: String) : Named() - data class Enum(val fullName: String) : Named() + public data class Enum(val fullName: String) : Named() - data class Record(val fullName: String) : Named() + public data class Record(val fullName: String) : Named() } override fun toString(): String { return this::class.simpleName!! } -} - -context(Encoder) -internal fun Schema.ensureTypeOf(type: Schema.Type) { - if (this.type != type) { - throw SerializationException("Schema $this must be of type $type to be used with ${this@ensureTypeOf::class}") - } } \ No newline at end of file diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/FixedEncoder.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/FixedEncoder.kt index 3af4e173..c0028476 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/FixedEncoder.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/FixedEncoder.kt @@ -1,6 +1,7 @@ package com.github.avrokotlin.avro4k.encoder import com.github.avrokotlin.avro4k.Avro +import com.github.avrokotlin.avro4k.schema.ensureTypeOf import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.SerialDescriptor import org.apache.avro.Schema diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/MapEncoder.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/MapEncoder.kt index 6950aca8..5c70c64f 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/MapEncoder.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/MapEncoder.kt @@ -1,6 +1,7 @@ package com.github.avrokotlin.avro4k.encoder import com.github.avrokotlin.avro4k.Avro +import com.github.avrokotlin.avro4k.schema.ensureTypeOf import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.SerialDescriptor import org.apache.avro.Schema diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/RecordEncoder.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/RecordEncoder.kt index 6acce032..a3dcf731 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/RecordEncoder.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/encoder/RecordEncoder.kt @@ -3,6 +3,7 @@ package com.github.avrokotlin.avro4k.encoder import com.github.avrokotlin.avro4k.Avro import com.github.avrokotlin.avro4k.ListRecord import com.github.avrokotlin.avro4k.internal.ElementDescriptor +import com.github.avrokotlin.avro4k.schema.ensureTypeOf import kotlinx.serialization.SerializationException import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.descriptors.SerialDescriptor diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/internal/EnumResolver.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/internal/EnumResolver.kt index 26c947e1..5b204cdb 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/internal/EnumResolver.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/internal/EnumResolver.kt @@ -4,7 +4,7 @@ import com.github.avrokotlin.avro4k.AvroEnumDefault import kotlinx.serialization.descriptors.SerialDescriptor import java.util.concurrent.ConcurrentHashMap -class EnumResolver { +internal class EnumResolver { private val defaultIndexCache: MutableMap = ConcurrentHashMap() private data class EnumDefault(val index: Int?) diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/internal/exceptions.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/internal/exceptions.kt index c08cd0e1..144deca4 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/internal/exceptions.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/internal/exceptions.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.encoding.Decoder import kotlin.reflect.KClass -class AvroSchemaGenerationException(message: String) : SerializationException(message) +internal class AvroSchemaGenerationException(message: String) : SerializationException(message) context(Decoder) internal fun DecodedNullError() = SerializationException("Unexpected null value, Decoder.decodeTaggedNotNullMark should be called first") diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/records.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/records.kt index d8ad4c22..6141b7e3 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/records.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/records.kt @@ -1,5 +1,6 @@ package com.github.avrokotlin.avro4k +import kotlinx.serialization.ExperimentalSerializationApi import org.apache.avro.Schema import org.apache.avro.generic.GenericRecord import org.apache.avro.specific.SpecificRecord @@ -8,13 +9,15 @@ import org.apache.avro.specific.SpecificRecord * An implementation of [org.apache.avro.generic.GenericContainer] that implements * both [GenericRecord] and [SpecificRecord]. */ -interface Record : GenericRecord, SpecificRecord +@ExperimentalSerializationApi +public interface Record : GenericRecord, SpecificRecord -data class ListRecord( +@ExperimentalSerializationApi +public data class ListRecord( private val s: Schema, private val values: List, ) : Record { - constructor(s: Schema, vararg values: Any?) : this(s, values.toList()) + public constructor(s: Schema, vararg values: Any?) : this(s, values.toList()) init { require(schema.type == Schema.Type.RECORD) { "Cannot create a Record with a schema that is not of type Schema.Type.RECORD [was $s]" } diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/FieldNamingStrategy.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/FieldNamingStrategy.kt index fd1bfe8d..63b7f1b4 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/FieldNamingStrategy.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/FieldNamingStrategy.kt @@ -1,28 +1,29 @@ package com.github.avrokotlin.avro4k.schema +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.SerialDescriptor -interface FieldNamingStrategy { - fun resolve( +public interface FieldNamingStrategy { + public fun resolve( descriptor: SerialDescriptor, elementIndex: Int, ): String - companion object Builtins { + public companion object Builtins { /** * Returns the field name as is. */ - object NoOp : FieldNamingStrategy { + public object NoOp : FieldNamingStrategy { override fun resolve( descriptor: SerialDescriptor, elementIndex: Int, - ) = descriptor.getElementName(elementIndex) + ): String = descriptor.getElementName(elementIndex) } /** * Convert the field name to snake_case by adding an underscore before each capital letter, and lowercase those capital letters. */ - object SnakeCase : FieldNamingStrategy { + public object SnakeCase : FieldNamingStrategy { override fun resolve( descriptor: SerialDescriptor, elementIndex: Int, @@ -65,7 +66,8 @@ interface FieldNamingStrategy { /** * Enforce camelCase naming strategy by upper-casing the first field name letter. */ - object PascalCase : FieldNamingStrategy { + @ExperimentalSerializationApi + public object PascalCase : FieldNamingStrategy { override fun resolve( descriptor: SerialDescriptor, elementIndex: Int, diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/SerialDescriptorVisitor.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/SerialDescriptorVisitor.kt index fead2db8..0ecb1b31 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/SerialDescriptorVisitor.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/SerialDescriptorVisitor.kt @@ -1,21 +1,13 @@ package com.github.avrokotlin.avro4k.schema -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.PrimitiveKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.StructureKind -import kotlinx.serialization.descriptors.capturedKClass -import kotlinx.serialization.descriptors.elementDescriptors -import kotlinx.serialization.descriptors.getContextualDescriptor -import kotlinx.serialization.descriptors.getPolymorphicDescriptors import kotlinx.serialization.modules.SerializersModule -import kotlinx.serialization.serializerOrNull -@ExperimentalSerializationApi -interface SerialDescriptorValueVisitor { +internal interface SerialDescriptorValueVisitor { val serializersModule: SerializersModule /** @@ -111,8 +103,7 @@ interface SerialDescriptorValueVisitor { } } -@ExperimentalSerializationApi -interface SerialDescriptorMapVisitor { +internal interface SerialDescriptorMapVisitor { /** * @return null if we don't want to visit the map key */ @@ -132,8 +123,7 @@ interface SerialDescriptorMapVisitor { fun endMapVisit(descriptor: SerialDescriptor) } -@ExperimentalSerializationApi -interface SerialDescriptorListVisitor { +internal interface SerialDescriptorListVisitor { /** * @return null if we don't want to visit the list item */ @@ -145,8 +135,7 @@ interface SerialDescriptorListVisitor { fun endListVisit(descriptor: SerialDescriptor) } -@ExperimentalSerializationApi -interface SerialDescriptorPolymorphicVisitor { +internal interface SerialDescriptorPolymorphicVisitor { /** * @return null if we don't want to visit the found polymorphic descriptor */ @@ -155,8 +144,7 @@ interface SerialDescriptorPolymorphicVisitor { fun endPolymorphicVisit(descriptor: SerialDescriptor) } -@ExperimentalSerializationApi -interface SerialDescriptorClassVisitor { +internal interface SerialDescriptorClassVisitor { /** * @return null if we don't want to visit the class element */ @@ -168,8 +156,7 @@ interface SerialDescriptorClassVisitor { fun endClassVisit(descriptor: SerialDescriptor) } -@ExperimentalSerializationApi -interface SerialDescriptorInlineClassVisitor { +internal interface SerialDescriptorInlineClassVisitor { /** * @return null if we don't want to visit the inline class element */ @@ -177,30 +164,4 @@ interface SerialDescriptorInlineClassVisitor { inlineClassDescriptor: SerialDescriptor, inlineElementIndex: Int, ): SerialDescriptorValueVisitor? -} - -@ExperimentalSerializationApi -@OptIn(InternalSerializationApi::class) -private fun SerialDescriptor.getNonNullContextualDescriptor(serializersModule: SerializersModule) = - requireNotNull(serializersModule.getContextualDescriptor(this) ?: this.capturedKClass?.serializerOrNull()?.descriptor) { - "No descriptor found in serialization context for $this" - } - -@ExperimentalSerializationApi -internal fun SerialDescriptor.possibleSerializationSubclasses(serializersModule: SerializersModule): Sequence { - return when (this.kind) { - PolymorphicKind.SEALED -> - elementDescriptors.asSequence() - .filter { it.kind == SerialKind.CONTEXTUAL } - .flatMap { it.elementDescriptors } - .flatMap { it.possibleSerializationSubclasses(serializersModule) } - - PolymorphicKind.OPEN -> - serializersModule.getPolymorphicDescriptors(this@possibleSerializationSubclasses).asSequence() - .flatMap { it.possibleSerializationSubclasses(serializersModule) } - - SerialKind.CONTEXTUAL -> sequenceOf(getNonNullContextualDescriptor(serializersModule)) - - else -> sequenceOf(this) - } } \ No newline at end of file diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/helpers.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/helpers.kt index 5b468d87..5784eb34 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/helpers.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/helpers.kt @@ -1,15 +1,27 @@ package com.github.avrokotlin.avro4k.schema +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.SerializationException +import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.descriptors.SerialKind +import kotlinx.serialization.descriptors.capturedKClass +import kotlinx.serialization.descriptors.elementDescriptors +import kotlinx.serialization.descriptors.getContextualDescriptor +import kotlinx.serialization.descriptors.getPolymorphicDescriptors +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.serializerOrNull import org.apache.avro.Schema -inline fun SerialDescriptor.findAnnotation() = annotations.firstNotNullOfOrNull { it as? T } +internal inline fun SerialDescriptor.findAnnotation() = annotations.firstNotNullOfOrNull { it as? T } -inline fun SerialDescriptor.findAnnotations() = annotations.filterIsInstance() +internal inline fun SerialDescriptor.findAnnotations() = annotations.filterIsInstance() -inline fun SerialDescriptor.findElementAnnotation(elementIndex: Int) = getElementAnnotations(elementIndex).firstNotNullOfOrNull { it as? T } +internal inline fun SerialDescriptor.findElementAnnotation(elementIndex: Int) = getElementAnnotations(elementIndex).firstNotNullOfOrNull { it as? T } -inline fun SerialDescriptor.findElementAnnotations(elementIndex: Int) = getElementAnnotations(elementIndex).filterIsInstance() +internal inline fun SerialDescriptor.findElementAnnotations(elementIndex: Int) = getElementAnnotations(elementIndex).filterIsInstance() internal val SerialDescriptor.nonNullSerialName: String get() = serialName.removeSuffix('?') @@ -52,12 +64,46 @@ internal fun Schema.overrideNamespace(namespaceOverride: String): Schema { Schema.Type.ENUM -> Schema.createEnum(name, doc, namespaceOverride, enumSymbols, enumDefault) .also { aliases.forEach { alias -> it.addAlias(alias) } } + Schema.Type.FIXED -> Schema.createFixed(name, doc, namespaceOverride, fixedSize) .also { aliases.forEach { alias -> it.addAlias(alias) } } + Schema.Type.MAP -> Schema.createMap(valueType.overrideNamespace(namespaceOverride)) Schema.Type.ARRAY -> Schema.createArray(elementType.overrideNamespace(namespaceOverride)) else -> this } .also { objectProps.forEach { prop -> it.addProp(prop.key, prop.value) } } -} \ No newline at end of file +} + +context(Encoder) +internal fun Schema.ensureTypeOf(type: Schema.Type) { + if (this.type != type) { + throw SerializationException("Schema $this must be of type $type to be used with ${this@ensureTypeOf::class}") + } +} + +@ExperimentalSerializationApi +internal fun SerialDescriptor.possibleSerializationSubclasses(serializersModule: SerializersModule): Sequence { + return when (this.kind) { + PolymorphicKind.SEALED -> + elementDescriptors.asSequence() + .filter { it.kind == SerialKind.CONTEXTUAL } + .flatMap { it.elementDescriptors } + .flatMap { it.possibleSerializationSubclasses(serializersModule) } + + PolymorphicKind.OPEN -> + serializersModule.getPolymorphicDescriptors(this@possibleSerializationSubclasses).asSequence() + .flatMap { it.possibleSerializationSubclasses(serializersModule) } + + SerialKind.CONTEXTUAL -> sequenceOf(getNonNullContextualDescriptor(serializersModule)) + + else -> sequenceOf(this) + } +} + +@OptIn(InternalSerializationApi::class) +internal fun SerialDescriptor.getNonNullContextualDescriptor(serializersModule: SerializersModule) = + requireNotNull(serializersModule.getContextualDescriptor(this) ?: this.capturedKClass?.serializerOrNull()?.descriptor) { + "No descriptor found in serialization context for $this" + } \ No newline at end of file diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/AvroSerializer.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/AvroSerializer.kt index a4b88094..07a26e71 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/AvroSerializer.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/AvroSerializer.kt @@ -6,7 +6,7 @@ import kotlinx.serialization.KSerializer import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -abstract class AvroSerializer : KSerializer { +public abstract class AvroSerializer : KSerializer { final override fun serialize( encoder: Encoder, value: T, @@ -24,14 +24,14 @@ abstract class AvroSerializer : KSerializer { * * Implement it to provide a generic serialization logic with the standard [Encoder]. */ - open fun serializeGeneric( + public open fun serializeGeneric( encoder: Encoder, value: T, ) { throw UnsupportedOperationException("The serializer ${this::class.qualifiedName} is not usable outside of Avro serialization.") } - abstract fun serializeAvro( + public abstract fun serializeAvro( encoder: AvroEncoder, value: T, ) @@ -43,9 +43,9 @@ abstract class AvroSerializer : KSerializer { return deserializeAvro(decoder) } - open fun deserializeGeneric(decoder: Decoder): T { + public open fun deserializeGeneric(decoder: Decoder): T { throw UnsupportedOperationException("The serializer ${this::class.qualifiedName} is not usable outside of Avro serialization.") } - abstract fun deserializeAvro(decoder: AvroDecoder): T + public abstract fun deserializeAvro(decoder: AvroDecoder): T } \ No newline at end of file diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/BigDecimalSerializer.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/BigDecimalSerializer.kt index 6e4ba02f..6dfb1d9c 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/BigDecimalSerializer.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/BigDecimalSerializer.kt @@ -13,6 +13,7 @@ import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.PrimitiveKind import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.descriptors.buildSerialDescriptor import kotlinx.serialization.encoding.Decoder @@ -28,7 +29,7 @@ import java.nio.ByteBuffer private val converter = Conversions.DecimalConversion() private val defaultAnnotation = AvroDecimal() -object BigDecimalSerializer : AvroSerializer(), AvroLogicalTypeSupplier { +public object BigDecimalSerializer : AvroSerializer(), AvroLogicalTypeSupplier { override fun getLogicalType(inlinedStack: List): LogicalType { return inlinedStack.firstNotNullOfOrNull { it.descriptor.findElementAnnotation(it.elementIndex ?: return@firstNotNullOfOrNull null)?.logicalType @@ -36,7 +37,7 @@ object BigDecimalSerializer : AvroSerializer(), AvroLogicalTypeSuppl } @OptIn(InternalSerializationApi::class) - override val descriptor = + override val descriptor: SerialDescriptor = buildSerialDescriptor(BigDecimal::class.qualifiedName!!, StructureKind.LIST) { element("item", buildSerialDescriptor("item", PrimitiveKind.BYTE)) this.annotations = listOf(AvroLogicalType(BigDecimalSerializer::class)) @@ -45,14 +46,20 @@ object BigDecimalSerializer : AvroSerializer(), AvroLogicalTypeSuppl override fun serializeAvro( encoder: AvroEncoder, value: BigDecimal, - ) = encodeBigDecimal(encoder, value) + ) { + encodeBigDecimal(encoder, value) + } override fun serializeGeneric( encoder: Encoder, value: BigDecimal, - ) = encoder.encodeString(value.toString()) + ) { + encoder.encodeString(value.toString()) + } - override fun deserializeAvro(decoder: AvroDecoder) = decodeBigDecimal(decoder) + override fun deserializeAvro(decoder: AvroDecoder): BigDecimal { + return decodeBigDecimal(decoder) + } override fun deserializeGeneric(decoder: Decoder): BigDecimal { return decoder.decodeString().toBigDecimal() @@ -64,20 +71,26 @@ object BigDecimalSerializer : AvroSerializer(), AvroLogicalTypeSuppl } } -object BigDecimalAsStringSerializer : AvroSerializer() { - override val descriptor = PrimitiveSerialDescriptor(BigDecimal::class.qualifiedName!!, PrimitiveKind.STRING) +public object BigDecimalAsStringSerializer : AvroSerializer() { + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(BigDecimal::class.qualifiedName!!, PrimitiveKind.STRING) override fun serializeAvro( encoder: AvroEncoder, value: BigDecimal, - ) = encodeBigDecimal(encoder, value) + ) { + encodeBigDecimal(encoder, value) + } override fun serializeGeneric( encoder: Encoder, value: BigDecimal, - ) = encoder.encodeString(value.toString()) + ) { + encoder.encodeString(value.toString()) + } - override fun deserializeAvro(decoder: AvroDecoder) = decodeBigDecimal(decoder) + override fun deserializeAvro(decoder: AvroDecoder): BigDecimal { + return decodeBigDecimal(decoder) + } override fun deserializeGeneric(decoder: Decoder): BigDecimal { return decoder.decodeString().toBigDecimal() diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/BigIntegerSerializer.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/BigIntegerSerializer.kt index 1ae78fe6..b0292017 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/BigIntegerSerializer.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/BigIntegerSerializer.kt @@ -6,29 +6,34 @@ import com.github.avrokotlin.avro4k.encoder.SchemaTypeMatcher import com.github.avrokotlin.avro4k.encoder.encodeValueResolved import kotlinx.serialization.descriptors.PrimitiveKind import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import org.apache.avro.Schema import java.math.BigInteger -object BigIntegerSerializer : AvroSerializer() { - override val descriptor = PrimitiveSerialDescriptor(BigInteger::class.qualifiedName!!, PrimitiveKind.STRING) +public object BigIntegerSerializer : AvroSerializer() { + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(BigInteger::class.qualifiedName!!, PrimitiveKind.STRING) override fun serializeAvro( encoder: AvroEncoder, value: BigInteger, - ) = encoder.encodeValueResolved( - SchemaTypeMatcher.Scalar.STRING to { value.toString() }, - SchemaTypeMatcher.Scalar.INT to { value.intValueExact() }, - SchemaTypeMatcher.Scalar.LONG to { value.longValueExact() }, - SchemaTypeMatcher.Scalar.FLOAT to { value.toFloat() }, - SchemaTypeMatcher.Scalar.DOUBLE to { value.toDouble() } - ) + ) { + encoder.encodeValueResolved( + SchemaTypeMatcher.Scalar.STRING to { value.toString() }, + SchemaTypeMatcher.Scalar.INT to { value.intValueExact() }, + SchemaTypeMatcher.Scalar.LONG to { value.longValueExact() }, + SchemaTypeMatcher.Scalar.FLOAT to { value.toFloat() }, + SchemaTypeMatcher.Scalar.DOUBLE to { value.toDouble() } + ) + } override fun serializeGeneric( encoder: Encoder, value: BigInteger, - ) = encoder.encodeString(value.toString()) + ) { + encoder.encodeString(value.toString()) + } override fun deserializeAvro(decoder: AvroDecoder): BigInteger = when (decoder.currentWriterSchema.type) { diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/URLSerializer.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/URLSerializer.kt index f8ee41d5..fb092deb 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/URLSerializer.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/URLSerializer.kt @@ -3,17 +3,20 @@ package com.github.avrokotlin.avro4k.serializer import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.PrimitiveKind import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import java.net.URL -object URLSerializer : KSerializer { - override val descriptor = PrimitiveSerialDescriptor(URL::class.qualifiedName!!, PrimitiveKind.STRING) +public object URLSerializer : KSerializer { + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(URL::class.qualifiedName!!, PrimitiveKind.STRING) override fun serialize( encoder: Encoder, value: URL, - ) = encoder.encodeString(value.toString()) + ) { + encoder.encodeString(value.toString()) + } override fun deserialize(decoder: Decoder): URL = URL(decoder.decodeString()) } \ No newline at end of file diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/UUIDSerializer.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/UUIDSerializer.kt index f9cb1b36..e63d1c8c 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/UUIDSerializer.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/UUIDSerializer.kt @@ -6,6 +6,7 @@ import com.github.avrokotlin.avro4k.AvroLogicalTypeSupplier import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.buildSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -13,9 +14,9 @@ import org.apache.avro.LogicalType import org.apache.avro.LogicalTypes import java.util.UUID -object UUIDSerializer : KSerializer, AvroLogicalTypeSupplier { +public object UUIDSerializer : KSerializer, AvroLogicalTypeSupplier { @OptIn(InternalSerializationApi::class) - override val descriptor = + override val descriptor: SerialDescriptor = buildSerialDescriptor("uuid", PrimitiveKind.STRING) { annotations = listOf(AvroLogicalType(UUIDSerializer::class)) } @@ -27,7 +28,9 @@ object UUIDSerializer : KSerializer, AvroLogicalTypeSupplier { override fun serialize( encoder: Encoder, value: UUID, - ) = encoder.encodeString(value.toString()) + ) { + encoder.encodeString(value.toString()) + } override fun deserialize(decoder: Decoder): UUID = UUID.fromString(decoder.decodeString()) } \ No newline at end of file diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/date.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/date.kt index 116f8369..c8e4aeaf 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/date.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/serializer/date.kt @@ -11,6 +11,7 @@ import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.buildSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -25,7 +26,7 @@ import java.time.ZoneOffset import java.time.temporal.ChronoUnit import kotlin.reflect.KClass -object LocalDateSerializer : AvroTimeSerializer(LocalDate::class, PrimitiveKind.INT) { +public object LocalDateSerializer : AvroTimeSerializer(LocalDate::class, PrimitiveKind.INT) { override fun getLogicalType(inlinedStack: List): LogicalType { return LogicalTypes.date() } @@ -33,34 +34,42 @@ object LocalDateSerializer : AvroTimeSerializer(LocalDate::class, Pri override fun serializeAvro( encoder: AvroEncoder, value: LocalDate, - ) = encoder.encodeValueResolved( - SchemaTypeMatcher.Scalar.INT to { - when (it.logicalType) { - is LogicalTypes.Date, null -> value.toEpochDay().toInt() - else -> it.logicalType.throwUnsupportedWith() - } - }, - SchemaTypeMatcher.Scalar.LONG to { - when (it.logicalType) { - // Date is not compatible with LONG, so we require a null logical type to encode the timestamp - null -> value.toEpochDay() - else -> it.logicalType.throwUnsupportedWith() - } - }, - SchemaTypeMatcher.Scalar.STRING to { value.toString() } - ) + ) { + encoder.encodeValueResolved( + SchemaTypeMatcher.Scalar.INT to { + when (it.logicalType) { + is LogicalTypes.Date, null -> value.toEpochDay().toInt() + else -> it.logicalType.throwUnsupportedWith() + } + }, + SchemaTypeMatcher.Scalar.LONG to { + when (it.logicalType) { + // Date is not compatible with LONG, so we require a null logical type to encode the timestamp + null -> value.toEpochDay() + else -> it.logicalType.throwUnsupportedWith() + } + }, + SchemaTypeMatcher.Scalar.STRING to { value.toString() } + ) + } override fun serializeGeneric( encoder: Encoder, value: LocalDate, - ) = encoder.encodeInt(value.toEpochDay().toInt()) + ) { + encoder.encodeInt(value.toEpochDay().toInt()) + } - override fun deserializeAvro(decoder: AvroDecoder): LocalDate = deserializeGeneric(decoder) + override fun deserializeAvro(decoder: AvroDecoder): LocalDate { + return deserializeGeneric(decoder) + } - override fun deserializeGeneric(decoder: Decoder) = LocalDate.ofEpochDay(decoder.decodeInt().toLong()) + override fun deserializeGeneric(decoder: Decoder): LocalDate { + return LocalDate.ofEpochDay(decoder.decodeInt().toLong()) + } } -object LocalTimeSerializer : AvroTimeSerializer(LocalTime::class, PrimitiveKind.INT) { +public object LocalTimeSerializer : AvroTimeSerializer(LocalTime::class, PrimitiveKind.INT) { override fun getLogicalType(inlinedStack: List): LogicalType { return LogicalTypes.timeMillis() } @@ -68,28 +77,32 @@ object LocalTimeSerializer : AvroTimeSerializer(LocalTime::class, Pri override fun serializeAvro( encoder: AvroEncoder, value: LocalTime, - ) = encoder.encodeValueResolved( - SchemaTypeMatcher.Scalar.INT to { - when (it.logicalType) { - is LogicalTypes.TimeMillis, null -> value.toMillisOfDay() - else -> it.logicalType.throwUnsupportedWith() - } - }, - SchemaTypeMatcher.Scalar.LONG to { - when (it.logicalType) { - // TimeMillis is not compatible with LONG, so we require a null logical type to encode the timestamp - null -> value.toMillisOfDay().toLong() - is LogicalTypes.TimeMicros -> value.toMicroOfDay() - else -> it.logicalType.throwUnsupportedWith() - } - }, - SchemaTypeMatcher.Scalar.STRING to { value.truncatedTo(ChronoUnit.MILLIS).toString() } - ) + ) { + encoder.encodeValueResolved( + SchemaTypeMatcher.Scalar.INT to { + when (it.logicalType) { + is LogicalTypes.TimeMillis, null -> value.toMillisOfDay() + else -> it.logicalType.throwUnsupportedWith() + } + }, + SchemaTypeMatcher.Scalar.LONG to { + when (it.logicalType) { + // TimeMillis is not compatible with LONG, so we require a null logical type to encode the timestamp + null -> value.toMillisOfDay().toLong() + is LogicalTypes.TimeMicros -> value.toMicroOfDay() + else -> it.logicalType.throwUnsupportedWith() + } + }, + SchemaTypeMatcher.Scalar.STRING to { value.truncatedTo(ChronoUnit.MILLIS).toString() } + ) + } override fun serializeGeneric( encoder: Encoder, value: LocalTime, - ) = encoder.encodeInt(value.toMillisOfDay()) + ) { + encoder.encodeInt(value.toMillisOfDay()) + } private fun LocalTime.toMillisOfDay() = (toNanoOfDay() / 1000000).toInt() @@ -109,7 +122,7 @@ object LocalTimeSerializer : AvroTimeSerializer(LocalTime::class, Pri } } -object LocalDateTimeSerializer : AvroTimeSerializer(LocalDateTime::class, PrimitiveKind.LONG) { +public object LocalDateTimeSerializer : AvroTimeSerializer(LocalDateTime::class, PrimitiveKind.LONG) { override fun getLogicalType(inlinedStack: List): LogicalType { return LogicalTypes.timestampMillis() } @@ -117,21 +130,25 @@ object LocalDateTimeSerializer : AvroTimeSerializer(LocalDateTime override fun serializeAvro( encoder: AvroEncoder, value: LocalDateTime, - ) = encoder.encodeValueResolved( - SchemaTypeMatcher.Scalar.LONG to { - when (it.logicalType) { - is LogicalTypes.TimestampMillis, null -> value.toInstant(ZoneOffset.UTC).toEpochMilli() - is LogicalTypes.TimestampMicros -> value.toInstant(ZoneOffset.UTC).toEpochMicros() - else -> it.logicalType.throwUnsupportedWith() - } - }, - SchemaTypeMatcher.Scalar.STRING to { value.truncatedTo(ChronoUnit.MILLIS).toString() } - ) + ) { + encoder.encodeValueResolved( + SchemaTypeMatcher.Scalar.LONG to { + when (it.logicalType) { + is LogicalTypes.TimestampMillis, null -> value.toInstant(ZoneOffset.UTC).toEpochMilli() + is LogicalTypes.TimestampMicros -> value.toInstant(ZoneOffset.UTC).toEpochMicros() + else -> it.logicalType.throwUnsupportedWith() + } + }, + SchemaTypeMatcher.Scalar.STRING to { value.truncatedTo(ChronoUnit.MILLIS).toString() } + ) + } override fun serializeGeneric( encoder: Encoder, value: LocalDateTime, - ) = encoder.encodeLong(value.toInstant(ZoneOffset.UTC).toEpochMilli()) + ) { + encoder.encodeLong(value.toInstant(ZoneOffset.UTC).toEpochMilli()) + } override fun deserializeAvro(decoder: AvroDecoder): LocalDateTime = deserializeGeneric(decoder) @@ -140,7 +157,7 @@ object LocalDateTimeSerializer : AvroTimeSerializer(LocalDateTime } } -object TimestampSerializer : AvroTimeSerializer(Timestamp::class, PrimitiveKind.LONG) { +public object TimestampSerializer : AvroTimeSerializer(Timestamp::class, PrimitiveKind.LONG) { override fun getLogicalType(inlinedStack: List): LogicalType { return LogicalTypes.timestampMillis() } @@ -148,21 +165,25 @@ object TimestampSerializer : AvroTimeSerializer(Timestamp::class, Pri override fun serializeAvro( encoder: AvroEncoder, value: Timestamp, - ) = encoder.encodeValueResolved( - SchemaTypeMatcher.Scalar.LONG to { - when (it.logicalType) { - is LogicalTypes.TimestampMillis, null -> value.toInstant().toEpochMilli() - is LogicalTypes.TimestampMicros -> value.toInstant().toEpochMicros() - else -> it.logicalType.throwUnsupportedWith() - } - }, - SchemaTypeMatcher.Scalar.STRING to { value.toInstant().toString() } - ) + ) { + encoder.encodeValueResolved( + SchemaTypeMatcher.Scalar.LONG to { + when (it.logicalType) { + is LogicalTypes.TimestampMillis, null -> value.toInstant().toEpochMilli() + is LogicalTypes.TimestampMicros -> value.toInstant().toEpochMicros() + else -> it.logicalType.throwUnsupportedWith() + } + }, + SchemaTypeMatcher.Scalar.STRING to { value.toInstant().toString() } + ) + } override fun serializeGeneric( encoder: Encoder, value: Timestamp, - ) = encoder.encodeLong(value.toInstant().toEpochMilli()) + ) { + encoder.encodeLong(value.toInstant().toEpochMilli()) + } override fun deserializeAvro(decoder: AvroDecoder): Timestamp = deserializeGeneric(decoder) @@ -171,7 +192,7 @@ object TimestampSerializer : AvroTimeSerializer(Timestamp::class, Pri } } -object InstantSerializer : AvroTimeSerializer(Instant::class, PrimitiveKind.LONG) { +public object InstantSerializer : AvroTimeSerializer(Instant::class, PrimitiveKind.LONG) { override fun getLogicalType(inlinedStack: List): LogicalType { return LogicalTypes.timestampMillis() } @@ -179,21 +200,25 @@ object InstantSerializer : AvroTimeSerializer(Instant::class, Primitive override fun serializeAvro( encoder: AvroEncoder, value: Instant, - ) = encoder.encodeValueResolved( - SchemaTypeMatcher.Scalar.LONG to { - when (it.logicalType) { - is LogicalTypes.TimestampMillis, null -> value.toEpochMilli() - is LogicalTypes.TimestampMicros -> value.toEpochMicros() - else -> it.logicalType.throwUnsupportedWith() - } - }, - SchemaTypeMatcher.Scalar.STRING to { value.toString() } - ) + ) { + encoder.encodeValueResolved( + SchemaTypeMatcher.Scalar.LONG to { + when (it.logicalType) { + is LogicalTypes.TimestampMillis, null -> value.toEpochMilli() + is LogicalTypes.TimestampMicros -> value.toEpochMicros() + else -> it.logicalType.throwUnsupportedWith() + } + }, + SchemaTypeMatcher.Scalar.STRING to { value.toString() } + ) + } override fun serializeGeneric( encoder: Encoder, value: Instant, - ) = encoder.encodeLong(value.toEpochMilli()) + ) { + encoder.encodeLong(value.toEpochMilli()) + } override fun deserializeAvro(decoder: AvroDecoder): Instant = deserializeGeneric(decoder) @@ -202,7 +227,7 @@ object InstantSerializer : AvroTimeSerializer(Instant::class, Primitive } } -object InstantToMicroSerializer : AvroTimeSerializer(Instant::class, PrimitiveKind.LONG) { +public object InstantToMicroSerializer : AvroTimeSerializer(Instant::class, PrimitiveKind.LONG) { override fun getLogicalType(inlinedStack: List): LogicalType { return LogicalTypes.timestampMicros() } @@ -210,21 +235,25 @@ object InstantToMicroSerializer : AvroTimeSerializer(Instant::class, Pr override fun serializeAvro( encoder: AvroEncoder, value: Instant, - ) = encoder.encodeValueResolved( - SchemaTypeMatcher.Scalar.LONG to { - when (it.logicalType) { - is LogicalTypes.TimestampMicros, null -> value.toEpochMicros() - is LogicalTypes.TimestampMillis -> value.toEpochMilli() - else -> it.logicalType.throwUnsupportedWith() - } - }, - SchemaTypeMatcher.Scalar.STRING to { value.toString() } - ) + ) { + encoder.encodeValueResolved( + SchemaTypeMatcher.Scalar.LONG to { + when (it.logicalType) { + is LogicalTypes.TimestampMicros, null -> value.toEpochMicros() + is LogicalTypes.TimestampMillis -> value.toEpochMilli() + else -> it.logicalType.throwUnsupportedWith() + } + }, + SchemaTypeMatcher.Scalar.STRING to { value.toString() } + ) + } override fun serializeGeneric( encoder: Encoder, value: Instant, - ) = encoder.encodeLong(value.toEpochMicros()) + ) { + encoder.encodeLong(value.toEpochMicros()) + } override fun deserializeAvro(decoder: AvroDecoder): Instant = deserializeGeneric(decoder) @@ -234,11 +263,11 @@ object InstantToMicroSerializer : AvroTimeSerializer(Instant::class, Pr } @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class) -abstract class AvroTimeSerializer( +public abstract class AvroTimeSerializer( klass: KClass, kind: PrimitiveKind, ) : AvroSerializer(), AvroLogicalTypeSupplier { - override val descriptor = + override val descriptor: SerialDescriptor = buildSerialDescriptor(klass.qualifiedName!!, kind) { annotations = listOf(AvroLogicalType(this@AvroTimeSerializer::class)) } diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/AvroAssertions.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/AvroAssertions.kt index 499f86ce..4138d1c7 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/AvroAssertions.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/AvroAssertions.kt @@ -17,7 +17,7 @@ import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.nio.file.Path -class AvroEncodingAssertions( +internal class AvroEncodingAssertions( private val valueToEncode: T, private val serializer: KSerializer, ) { @@ -134,7 +134,7 @@ class AvroEncodingAssertions( } } -open class AvroSchemaAssertions( +internal open class AvroSchemaAssertions( private val serializer: KSerializer, private var avro: Avro = Avro {}, ) { @@ -158,7 +158,7 @@ open class AvroSchemaAssertions( } } -object AvroAssertions { +internal object AvroAssertions { inline fun assertThat(): AvroSchemaAssertions { return AvroSchemaAssertions(Avro.serializersModule.serializer()) } @@ -180,5 +180,5 @@ object AvroAssertions { } } -val Schema.nullable: Schema +internal val Schema.nullable: Schema get() = Schema.createUnion(listOf(Schema.create(Schema.Type.NULL), this)) \ No newline at end of file diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/AvroObjectContainerFileTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/AvroObjectContainerFileTest.kt index 2f503ff6..a8cf6fed 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/AvroObjectContainerFileTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/AvroObjectContainerFileTest.kt @@ -13,7 +13,7 @@ import org.apache.avro.generic.GenericRecord import java.io.ByteArrayOutputStream import java.util.UUID -class AvroObjectContainerFileTest : StringSpec({ +internal class AvroObjectContainerFileTest : StringSpec({ val firstProfile = UserProfile( id = UserId(UUID.randomUUID()), diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/AvroSingleObjectTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/AvroSingleObjectTest.kt index d04f07a2..73ef80bc 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/AvroSingleObjectTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/AvroSingleObjectTest.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable import org.apache.avro.SchemaNormalization import java.time.Instant -class AvroSingleObjectTest : StringSpec({ +internal class AvroSingleObjectTest : StringSpec({ val orderEvent = OrderEvent( OrderId("123"), diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/RecordBuilderForTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/RecordBuilderForTest.kt index a6defe0e..adb38625 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/RecordBuilderForTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/RecordBuilderForTest.kt @@ -9,7 +9,7 @@ import org.apache.avro.generic.GenericRecord import org.apache.avro.generic.IndexedRecord import java.nio.ByteBuffer -data class RecordBuilderForTest( +internal data class RecordBuilderForTest( val fields: List, val explicitSchema: Schema? = null, ) { @@ -23,7 +23,7 @@ data class RecordBuilderForTest( } } -fun convertToAvroGenericValue( +internal fun convertToAvroGenericValue( value: Any?, schema: Schema, ): Any? { @@ -38,7 +38,7 @@ fun convertToAvroGenericValue( } } -fun normalizeGenericData(value: Any?): Any? { +internal fun normalizeGenericData(value: Any?): Any? { return when (value) { is IndexedRecord -> RecordBuilderForTest( @@ -81,11 +81,11 @@ private fun createMap( return value.mapValues { convertToAvroGenericValue(it.value, valueSchema) } } -fun record(vararg fields: Any?): RecordBuilderForTest { +internal fun record(vararg fields: Any?): RecordBuilderForTest { return RecordBuilderForTest(listOf(*fields)) } -fun recordWithSchema( +internal fun recordWithSchema( schema: Schema, vararg fields: Any?, ): RecordBuilderForTest { diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/dataClassesForTests.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/dataClassesForTests.kt index d2af111d..552a3110 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/dataClassesForTests.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/dataClassesForTests.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -enum class SomeEnum { +internal enum class SomeEnum { A, B, C, @@ -12,44 +12,44 @@ enum class SomeEnum { @Serializable @SerialName("RecordWithGenericField") -data class RecordWithGenericField(val value: T) +internal data class RecordWithGenericField(val value: T) @Serializable @JvmInline -value class WrappedBoolean(val value: Boolean) +internal value class WrappedBoolean(val value: Boolean) @Serializable @JvmInline -value class WrappedByte(val value: Byte) +internal value class WrappedByte(val value: Byte) @Serializable @JvmInline -value class WrappedChar(val value: Char) +internal value class WrappedChar(val value: Char) @Serializable @JvmInline -value class WrappedShort(val value: Short) +internal value class WrappedShort(val value: Short) @Serializable @JvmInline -value class WrappedInt(val value: Int) +internal value class WrappedInt(val value: Int) @Serializable @JvmInline -value class WrappedLong(val value: Long) +internal value class WrappedLong(val value: Long) @Serializable @JvmInline -value class WrappedFloat(val value: Float) +internal value class WrappedFloat(val value: Float) @Serializable @JvmInline -value class WrappedDouble(val value: Double) +internal value class WrappedDouble(val value: Double) @Serializable @JvmInline -value class WrappedString(val value: String) +internal value class WrappedString(val value: String) @Serializable @JvmInline -value class WrappedEnum(val value: SomeEnum) \ No newline at end of file +internal value class WrappedEnum(val value: SomeEnum) \ No newline at end of file diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/ArrayEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/ArrayEncodingTest.kt index 0d7d9392..9a54145e 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/ArrayEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/ArrayEncodingTest.kt @@ -5,7 +5,7 @@ import com.github.avrokotlin.avro4k.record import io.kotest.core.spec.style.StringSpec import kotlinx.serialization.Serializable -class ArrayEncodingTest : StringSpec({ +internal class ArrayEncodingTest : StringSpec({ "support array of booleans" { @Serializable data class TestArrayBooleans(val booleans: List) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroAliasEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroAliasEncodingTest.kt index 562d61fe..dad51225 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroAliasEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroAliasEncodingTest.kt @@ -12,7 +12,7 @@ import org.apache.avro.Schema import org.apache.avro.SchemaBuilder import org.apache.avro.generic.GenericData -class AvroAliasEncodingTest : StringSpec({ +internal class AvroAliasEncodingTest : StringSpec({ "support alias on field" { AvroAssertions.assertThat(EncodedField("hello")) .isEncodedAs(record("hello")) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroDefaultEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroDefaultEncodingTest.kt index f11d6516..2514d2b2 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroDefaultEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroDefaultEncodingTest.kt @@ -10,7 +10,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import java.math.BigDecimal -class AvroDefaultEncodingTest : StringSpec({ +internal class AvroDefaultEncodingTest : StringSpec({ "test default values correctly decoded" { AvroAssertions.assertThat(ContainerWithoutDefaultFields("abc")) .isEncodedAs(record("abc")) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroFixedEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroFixedEncodingTest.kt index 86b4a25d..01443008 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroFixedEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/AvroFixedEncodingTest.kt @@ -14,7 +14,7 @@ import kotlinx.serialization.SerializationException import org.apache.avro.generic.GenericData import kotlin.io.path.Path -class AvroFixedEncodingTest : StringSpec({ +internal class AvroFixedEncodingTest : StringSpec({ "support fixed on data class fields" { AvroAssertions.assertThat() .generatesSchema(Path("/fixed_string.json")) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/BytesEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/BytesEncodingTest.kt index be1c9298..edab2402 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/BytesEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/BytesEncodingTest.kt @@ -6,7 +6,7 @@ import io.kotest.core.spec.style.StringSpec import kotlinx.serialization.Serializable import org.apache.avro.Schema -class BytesEncodingTest : StringSpec({ +internal class BytesEncodingTest : StringSpec({ "encode/decode ByteArray" { AvroAssertions.assertThat(ByteArrayTest(byteArrayOf(1, 4, 9))) .isEncodedAs(record(byteArrayOf(1, 4, 9))) @@ -38,7 +38,7 @@ class BytesEncodingTest : StringSpec({ } }) { @Serializable - data class ByteArrayTest(val z: ByteArray) { + private data class ByteArrayTest(val z: ByteArray) { override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false @@ -54,7 +54,7 @@ class BytesEncodingTest : StringSpec({ } @Serializable - data class ArrayByteTest(val z: Array) { + private data class ArrayByteTest(val z: Array) { override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false @@ -70,5 +70,5 @@ class BytesEncodingTest : StringSpec({ } @Serializable - data class ListByteTest(val z: List) + private data class ListByteTest(val z: List) } \ No newline at end of file diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/EnumEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/EnumEncodingTest.kt index d46e3d24..a42ad64f 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/EnumEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/EnumEncodingTest.kt @@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import org.apache.avro.generic.GenericData -class EnumEncodingTest : StringSpec({ +internal class EnumEncodingTest : StringSpec({ "read / write enums" { AvroAssertions.assertThat(EnumTest(Cream.Bruce, BBM.Moore)) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/LogicalTypesEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/LogicalTypesEncodingTest.kt index f90d08c4..bffe7d2c 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/LogicalTypesEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/LogicalTypesEncodingTest.kt @@ -22,7 +22,7 @@ import java.time.LocalDateTime import java.time.LocalTime import java.util.UUID -class LogicalTypesEncodingTest : StringSpec({ +internal class LogicalTypesEncodingTest : StringSpec({ "support logical types at root level" { val schema = Avro.schema().fields[0].schema() AvroAssertions.assertThat(BigDecimal("123.45")) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/MapEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/MapEncodingTest.kt index 2d94d97b..55cf3f95 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/MapEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/MapEncodingTest.kt @@ -38,7 +38,7 @@ import org.apache.avro.SchemaBuilder import kotlin.io.path.Path @OptIn(InternalSerializationApi::class) -class MapSchemaTest : FunSpec({ +internal class MapEncodingTest : FunSpec({ test("generate map type for a Map of ints") { val map = mapOf("a" to 1, "b" to 20, "c" to 5) AvroAssertions.assertThat(StringIntTest(map)) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/NestedClassEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/NestedClassEncodingTest.kt index d71c5867..aaa332c2 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/NestedClassEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/NestedClassEncodingTest.kt @@ -6,7 +6,7 @@ import com.github.avrokotlin.avro4k.record import io.kotest.core.spec.style.StringSpec import kotlinx.serialization.Serializable -class NestedClassEncodingTest : StringSpec({ +internal class NestedClassEncodingTest : StringSpec({ "decode nested class" { AvroAssertions.assertThat(Birthplace(person = "Sammy Sam", town = Town(name = "Hardwick", population = 123))) .isEncodedAs( diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/PrimitiveEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/PrimitiveEncodingTest.kt index 0fd3f789..d98295ca 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/PrimitiveEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/PrimitiveEncodingTest.kt @@ -15,7 +15,7 @@ import io.kotest.core.spec.style.StringSpec import kotlinx.serialization.Serializable import java.nio.ByteBuffer -class PrimitiveEncodingTest : StringSpec({ +internal class PrimitiveEncodingTest : StringSpec({ "read write out booleans" { AvroAssertions.assertThat(BooleanTest(true)) .isEncodedAs(record(true)) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/RecordEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/RecordEncodingTest.kt index 2c20c429..31395553 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/RecordEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/RecordEncodingTest.kt @@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.SerializationException import org.apache.avro.SchemaBuilder -class RecordEncodingTest : StringSpec({ +internal class RecordEncodingTest : StringSpec({ "encoding basic data class" { val input = Foo( diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/SealedClassEncodingTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/SealedClassEncodingTest.kt index fa8b1227..83c20bb2 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/SealedClassEncodingTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/encoding/SealedClassEncodingTest.kt @@ -8,7 +8,7 @@ import com.github.avrokotlin.avro4k.schema import io.kotest.core.spec.style.StringSpec import kotlinx.serialization.Serializable -class SealedClassEncodingTest : StringSpec({ +internal class SealedClassEncodingTest : StringSpec({ "encode/decode sealed classes" { AvroAssertions.assertThat(ReferencingSealedClass(Operation.Binary.Add(1, 2))) .isEncodedAs(record(recordWithSchema(Avro.schema(), 1, 2))) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ArraySchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ArraySchemaTest.kt index c85af420..c2f7b0bb 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ArraySchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ArraySchemaTest.kt @@ -5,7 +5,7 @@ import io.kotest.core.spec.style.WordSpec import kotlinx.serialization.Serializable import kotlin.io.path.Path -class ArraySchemaTest : WordSpec({ +internal class ArraySchemaTest : WordSpec({ "SchemaEncoder" should { "generate array type for an Array of primitives" { diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroAliasSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroAliasSchemaTest.kt index 877f18ba..302a4e51 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroAliasSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroAliasSchemaTest.kt @@ -6,7 +6,7 @@ import io.kotest.core.spec.style.WordSpec import kotlinx.serialization.Serializable import kotlin.io.path.Path -class AvroAliasSchemaTest : WordSpec({ +internal class AvroAliasSchemaTest : WordSpec({ "SchemaEncoder" should { "support alias annotations on types" { diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroDefaultSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroDefaultSchemaTest.kt index 092211c9..64414c59 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroDefaultSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroDefaultSchemaTest.kt @@ -12,7 +12,7 @@ import org.apache.avro.AvroTypeException import java.math.BigDecimal import kotlin.io.path.Path -class AvroDefaultSchemaTest : FunSpec() { +internal class AvroDefaultSchemaTest : FunSpec() { init { test("schema for data class with @AvroDefault should include default value as a string") { AvroAssertions.assertThat() diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroDocSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroDocSchemaTest.kt index 8a53f1e7..ded56e82 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroDocSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroDocSchemaTest.kt @@ -6,7 +6,7 @@ import io.kotest.core.spec.style.WordSpec import kotlinx.serialization.Serializable import kotlin.io.path.Path -class AvroDocSchemaTest : WordSpec({ +internal class AvroDocSchemaTest : WordSpec({ "@AvroDoc" should { "support doc annotation on class" { diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroLogicalTypeTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroLogicalTypeTest.kt index 7598ac37..94e20115 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroLogicalTypeTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroLogicalTypeTest.kt @@ -9,7 +9,7 @@ import kotlinx.serialization.Serializable import org.apache.avro.LogicalType import org.apache.avro.Schema -class AvroLogicalTypeTest : StringSpec({ +internal class AvroLogicalTypeTest : StringSpec({ "@AvroLogicalType annotation should be supported" { AvroAssertions.assertThat() .generatesSchema(CustomLogicalType.addToSchema(Schema.create(Schema.Type.STRING))) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroNameTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroNameTest.kt index 89a6710d..c09d0acf 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroNameTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroNameTest.kt @@ -6,7 +6,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.io.path.Path -class AvroNameSchemaTest : FunSpec({ +internal class AvroNameSchemaTest : FunSpec({ test("Change field and class name") { AvroAssertions.assertThat() diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroNamespaceOverrideSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroNamespaceOverrideSchemaTest.kt index 330ea636..88ec995c 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroNamespaceOverrideSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroNamespaceOverrideSchemaTest.kt @@ -14,7 +14,7 @@ import org.apache.avro.Schema import org.apache.avro.SchemaBuilder import kotlin.io.path.Path -class AvroNamespaceOverrideSchemaTest : FunSpec({ +internal class AvroNamespaceOverrideSchemaTest : FunSpec({ test("support namespace annotations on records") { val schema = Avro.schema() diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroPropsSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroPropsSchemaTest.kt index 0ed57a63..66da7422 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroPropsSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroPropsSchemaTest.kt @@ -7,7 +7,7 @@ import io.kotest.core.spec.style.StringSpec import kotlinx.serialization.Serializable import kotlin.io.path.Path -class AvroPropsSchemaTest : StringSpec({ +internal class AvroPropsSchemaTest : StringSpec({ "should support props annotation on class" { AvroAssertions.assertThat() .generatesSchema(Path("/props_json_annotation_class.json")) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroSchemaTest.kt index 832a7a76..e93437c7 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroSchemaTest.kt @@ -9,7 +9,7 @@ import kotlinx.serialization.Serializable import org.apache.avro.Schema import org.apache.avro.SchemaBuilder -class AvroSchemaTest : StringSpec({ +internal class AvroSchemaTest : StringSpec({ "@AvroLogicalType annotation should be supported" { AvroAssertions.assertThat() .generatesSchema(SchemaBuilder.fixed("myCustomSchema").doc("a doc").size(42)) @@ -22,7 +22,7 @@ class AvroSchemaTest : StringSpec({ ) } -object CustomSchemaSupplier : AvroSchemaSupplier { +internal object CustomSchemaSupplier : AvroSchemaSupplier { override fun getSchema(stack: List): Schema { return Schema.createFixed("myCustomSchema", "a doc", null, 42) } diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BasicSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BasicSchemaTest.kt index 2771211b..ba2dec4d 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BasicSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BasicSchemaTest.kt @@ -5,7 +5,7 @@ import io.kotest.core.spec.style.FunSpec import kotlinx.serialization.Serializable import kotlin.io.path.Path -class BasicSchemaTest : FunSpec({ +internal class BasicSchemaTest : FunSpec({ test("schema for basic types") { AvroAssertions.assertThat() diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BigDecimalSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BigDecimalSchemaTest.kt index aa7262a8..711c946e 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BigDecimalSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BigDecimalSchemaTest.kt @@ -12,7 +12,7 @@ import org.apache.avro.LogicalTypes import org.apache.avro.Schema import java.math.BigDecimal -class BigDecimalSchemaTest : FunSpec({ +internal class BigDecimalSchemaTest : FunSpec({ test("support BigDecimal logical types") { AvroAssertions.assertThat() .generatesSchema(LogicalTypes.decimal(8, 2).addToSchema(Schema.create(Schema.Type.BYTES))) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BigIntegerSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BigIntegerSchemaTest.kt index ba872ab1..66ebc4aa 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BigIntegerSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BigIntegerSchemaTest.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable import org.apache.avro.Schema import java.math.BigInteger -class BigIntegerSchemaTest : FunSpec({ +internal class BigIntegerSchemaTest : FunSpec({ test("support BigInteger as string") { AvroAssertions.assertThat() .generatesSchema(Schema.create(Schema.Type.STRING)) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BytesSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BytesSchemaTest.kt index 6f95be9d..a8bdbb8b 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BytesSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/BytesSchemaTest.kt @@ -10,7 +10,7 @@ import kotlinx.serialization.serializer import org.apache.avro.Schema @OptIn(InternalSerializationApi::class) -class BytesSchemaTest : FunSpec({ +internal class BytesSchemaTest : FunSpec({ listOf( WrappedByteArray::class, diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ContextualSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ContextualSchemaTest.kt index 6053009a..fa928a9f 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ContextualSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ContextualSchemaTest.kt @@ -14,7 +14,7 @@ import kotlinx.serialization.modules.contextual import java.time.Instant import kotlin.io.path.Path -class ContextualSchemaTest : StringSpec({ +internal class ContextualSchemaTest : StringSpec({ "schema for contextual serializer" { AvroAssertions.assertThat() diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/DateSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/DateSchemaTest.kt index 0f459a3d..b15cfd7e 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/DateSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/DateSchemaTest.kt @@ -14,7 +14,7 @@ import kotlinx.serialization.builtins.nullable import org.apache.avro.LogicalTypes import org.apache.avro.Schema -class DateSchemaTest : FunSpec({ +internal class DateSchemaTest : FunSpec({ listOf( LocalDateSerializer to LogicalTypes.date().addToSchema(Schema.create(Schema.Type.INT)), LocalTimeSerializer to LogicalTypes.timeMillis().addToSchema(Schema.create(Schema.Type.INT)), diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/EnumSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/EnumSchemaTest.kt index 96ad1afa..fb306160 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/EnumSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/EnumSchemaTest.kt @@ -13,7 +13,7 @@ import io.kotest.core.spec.style.StringSpec import kotlinx.serialization.Serializable import kotlin.io.path.Path -class EnumSchemaTest : StringSpec({ +internal class EnumSchemaTest : StringSpec({ "should generate schema with alias, enum default and doc" { AvroAssertions.assertThat() .generatesSchema(Path("/enum_with_default.json")) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/FieldNamingStrategySchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/FieldNamingStrategySchemaTest.kt index f92f18c3..3157ade6 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/FieldNamingStrategySchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/FieldNamingStrategySchemaTest.kt @@ -5,7 +5,7 @@ import io.kotest.core.spec.style.StringSpec import kotlinx.serialization.Serializable import kotlin.io.path.Path -class FieldNamingStrategySchemaTest : StringSpec({ +internal class FieldNamingStrategySchemaTest : StringSpec({ "should convert schema with snake_case to camelCase" { AvroAssertions.assertThat() .withConfig { fieldNamingStrategy = FieldNamingStrategy.Builtins.SnakeCase } diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ImplicitNullsSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ImplicitNullsSchemaTest.kt index 12b14e29..b8ce64c9 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ImplicitNullsSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/ImplicitNullsSchemaTest.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.io.path.Path -class ImplicitNullsSchemaTest : FunSpec({ +internal class ImplicitNullsSchemaTest : FunSpec({ test("Should set default value to null for nullable fields when implicitNulls is true") { AvroAssertions.assertThat() .withConfig { implicitNulls = true } diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/PrimitiveSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/PrimitiveSchemaTest.kt index 22406543..5f238f02 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/PrimitiveSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/PrimitiveSchemaTest.kt @@ -18,7 +18,7 @@ import kotlinx.serialization.serializer import org.apache.avro.Schema @OptIn(InternalSerializationApi::class) -class PrimitiveSchemaTest : StringSpec({ +internal class PrimitiveSchemaTest : StringSpec({ listOf( WrappedBoolean::class to Schema.Type.BOOLEAN, WrappedByte::class to Schema.Type.INT, diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/RecursiveSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/RecursiveSchemaTest.kt index 36375bd1..f2fa59f1 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/RecursiveSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/RecursiveSchemaTest.kt @@ -5,7 +5,7 @@ import io.kotest.core.spec.style.FunSpec import kotlinx.serialization.Serializable import kotlin.io.path.Path -class RecursiveSchemaTest : FunSpec({ +internal class RecursiveSchemaTest : FunSpec({ test("accept direct recursive classes") { AvroAssertions.assertThat() diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/TransientSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/TransientSchemaTest.kt index 0ee57d85..a5d4b3b6 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/TransientSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/TransientSchemaTest.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.Transient import org.apache.avro.Schema import org.apache.avro.SchemaBuilder -class TransientSchemaTest : FunSpec({ +internal class TransientSchemaTest : FunSpec({ test("ignore fields with @Transient") { AvroAssertions.assertThat() .generatesSchema( diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/URLSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/URLSchemaTest.kt index 82ebf3a2..acba611c 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/URLSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/URLSchemaTest.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable import org.apache.avro.Schema import java.net.URL -class URLSchemaTest : FunSpec({ +internal class URLSchemaTest : FunSpec({ test("accept URL as String") { AvroAssertions.assertThat() .generatesSchema(Schema.create(Schema.Type.STRING)) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/UUIDSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/UUIDSchemaTest.kt index 2216ac77..8f8fe9bc 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/UUIDSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/UUIDSchemaTest.kt @@ -9,7 +9,7 @@ import org.apache.avro.LogicalTypes import org.apache.avro.Schema import java.util.UUID -class UUIDSchemaTest : FunSpec({ +internal class UUIDSchemaTest : FunSpec({ test("support UUID logical types") { AvroAssertions.assertThat() .generatesSchema(LogicalTypes.uuid().addToSchema(Schema.create(Schema.Type.STRING))) diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/UnionSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/UnionSchemaTest.kt index ac082011..277a0f7a 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/UnionSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/UnionSchemaTest.kt @@ -15,7 +15,7 @@ import kotlinx.serialization.modules.polymorphic import kotlinx.serialization.modules.subclass import kotlin.io.path.Path -class SealedClassSchemaTest : StringSpec({ +internal class SealedClassSchemaTest : StringSpec({ "should throw error when no implementation for an abstract class" { shouldThrow { Avro.schema(Operation.Binary.serializer()) diff --git a/src/test/resources/class_of_list_of_maps.json b/src/test/resources/class_of_list_of_maps.json index 136b6c84..90229b20 100644 --- a/src/test/resources/class_of_list_of_maps.json +++ b/src/test/resources/class_of_list_of_maps.json @@ -1,7 +1,7 @@ { "type": "record", "name": "List2Test", - "namespace": "com.github.avrokotlin.avro4k.encoding.MapSchemaTest", + "namespace": "com.github.avrokotlin.avro4k.encoding.MapEncodingTest", "fields": [ { "name": "ship", diff --git a/src/test/resources/list_of_maps.json b/src/test/resources/list_of_maps.json index 87101774..222ede7f 100644 --- a/src/test/resources/list_of_maps.json +++ b/src/test/resources/list_of_maps.json @@ -1,7 +1,7 @@ { "type": "record", "name": "ListTest", - "namespace": "com.github.avrokotlin.avro4k.encoding.MapSchemaTest", + "namespace": "com.github.avrokotlin.avro4k.encoding.MapEncodingTest", "fields": [ { "name": "list", diff --git a/src/test/resources/map_boolean_null.json b/src/test/resources/map_boolean_null.json index 115c6341..ac2690d6 100644 --- a/src/test/resources/map_boolean_null.json +++ b/src/test/resources/map_boolean_null.json @@ -1,7 +1,7 @@ { "type": "record", "name": "StringBooleanTest", - "namespace": "com.github.avrokotlin.avro4k.encoding.MapSchemaTest", + "namespace": "com.github.avrokotlin.avro4k.encoding.MapEncodingTest", "fields": [ { "name": "map", diff --git a/src/test/resources/map_int.json b/src/test/resources/map_int.json index f0e80a0c..1c0aaff5 100644 --- a/src/test/resources/map_int.json +++ b/src/test/resources/map_int.json @@ -1,7 +1,7 @@ { "type": "record", "name": "StringIntTest", - "namespace": "com.github.avrokotlin.avro4k.encoding.MapSchemaTest", + "namespace": "com.github.avrokotlin.avro4k.encoding.MapEncodingTest", "fields": [ { "name": "map", diff --git a/src/test/resources/map_record.json b/src/test/resources/map_record.json index 80957549..d26ee822 100644 --- a/src/test/resources/map_record.json +++ b/src/test/resources/map_record.json @@ -1,7 +1,7 @@ { "type": "record", "name": "StringNestedTest", - "namespace": "com.github.avrokotlin.avro4k.encoding.MapSchemaTest", + "namespace": "com.github.avrokotlin.avro4k.encoding.MapEncodingTest", "fields": [ { "name": "map", diff --git a/src/test/resources/map_set_nested.json b/src/test/resources/map_set_nested.json index 1c2d6b44..04122cba 100644 --- a/src/test/resources/map_set_nested.json +++ b/src/test/resources/map_set_nested.json @@ -1,7 +1,7 @@ { "type": "record", "name": "StringSetNestedTest", - "namespace": "com.github.avrokotlin.avro4k.encoding.MapSchemaTest", + "namespace": "com.github.avrokotlin.avro4k.encoding.MapEncodingTest", "fields": [ { "name": "map", diff --git a/src/test/resources/set_of_maps.json b/src/test/resources/set_of_maps.json index 83df9641..6dc91890 100644 --- a/src/test/resources/set_of_maps.json +++ b/src/test/resources/set_of_maps.json @@ -1,7 +1,7 @@ { "type": "record", "name": "SetTest", - "namespace": "com.github.avrokotlin.avro4k.encoding.MapSchemaTest", + "namespace": "com.github.avrokotlin.avro4k.encoding.MapEncodingTest", "fields": [ { "name": "set",