Skip to content

Commit

Permalink
Move integrations to main repo + new Ktor client integration
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Jan 25, 2025
1 parent e843a55 commit 392eff6
Show file tree
Hide file tree
Showing 65 changed files with 1,815 additions and 13 deletions.
163 changes: 163 additions & 0 deletions arrow-libs/integrations/arrow-core-jackson/api/arrow-core-jackson.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
public final class arrow/integrations/jackson/module/ArrowModuleKt {
public static final fun registerArrowModule (Lcom/fasterxml/jackson/databind/ObjectMapper;Larrow/integrations/jackson/module/EitherModuleConfig;Larrow/integrations/jackson/module/IorModuleConfig;)Lcom/fasterxml/jackson/databind/ObjectMapper;
public static synthetic fun registerArrowModule$default (Lcom/fasterxml/jackson/databind/ObjectMapper;Larrow/integrations/jackson/module/EitherModuleConfig;Larrow/integrations/jackson/module/IorModuleConfig;ILjava/lang/Object;)Lcom/fasterxml/jackson/databind/ObjectMapper;
}

public final class arrow/integrations/jackson/module/EitherDeserializerResolver : com/fasterxml/jackson/databind/deser/Deserializers$Base {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun findBeanDeserializer (Lcom/fasterxml/jackson/databind/JavaType;Lcom/fasterxml/jackson/databind/DeserializationConfig;Lcom/fasterxml/jackson/databind/BeanDescription;)Lcom/fasterxml/jackson/databind/JsonDeserializer;
}

public final class arrow/integrations/jackson/module/EitherModule : com/fasterxml/jackson/databind/module/SimpleModule {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun setupModule (Lcom/fasterxml/jackson/databind/Module$SetupContext;)V
}

public final class arrow/integrations/jackson/module/EitherModuleConfig {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;)Larrow/integrations/jackson/module/EitherModuleConfig;
public static synthetic fun copy$default (Larrow/integrations/jackson/module/EitherModuleConfig;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Larrow/integrations/jackson/module/EitherModuleConfig;
public fun equals (Ljava/lang/Object;)Z
public final fun getLeftFieldName ()Ljava/lang/String;
public final fun getRightFieldName ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class arrow/integrations/jackson/module/EitherSerializerResolver : com/fasterxml/jackson/databind/ser/Serializers$Base {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun findSerializer (Lcom/fasterxml/jackson/databind/SerializationConfig;Lcom/fasterxml/jackson/databind/JavaType;Lcom/fasterxml/jackson/databind/BeanDescription;)Lcom/fasterxml/jackson/databind/JsonSerializer;
}

public final class arrow/integrations/jackson/module/IorDeserializerResolver : com/fasterxml/jackson/databind/deser/Deserializers$Base {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun findBeanDeserializer (Lcom/fasterxml/jackson/databind/JavaType;Lcom/fasterxml/jackson/databind/DeserializationConfig;Lcom/fasterxml/jackson/databind/BeanDescription;)Lcom/fasterxml/jackson/databind/JsonDeserializer;
}

public final class arrow/integrations/jackson/module/IorModule : com/fasterxml/jackson/databind/module/SimpleModule {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun setupModule (Lcom/fasterxml/jackson/databind/Module$SetupContext;)V
}

public final class arrow/integrations/jackson/module/IorModuleConfig {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;)Larrow/integrations/jackson/module/IorModuleConfig;
public static synthetic fun copy$default (Larrow/integrations/jackson/module/IorModuleConfig;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Larrow/integrations/jackson/module/IorModuleConfig;
public fun equals (Ljava/lang/Object;)Z
public final fun getLeftFieldName ()Ljava/lang/String;
public final fun getRightFieldName ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class arrow/integrations/jackson/module/IorSerializerResolver : com/fasterxml/jackson/databind/ser/Serializers$Base {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun findSerializer (Lcom/fasterxml/jackson/databind/SerializationConfig;Lcom/fasterxml/jackson/databind/JavaType;Lcom/fasterxml/jackson/databind/BeanDescription;)Lcom/fasterxml/jackson/databind/JsonSerializer;
}

public final class arrow/integrations/jackson/module/OptionDeserializer : com/fasterxml/jackson/databind/JsonDeserializer, com/fasterxml/jackson/databind/deser/ContextualDeserializer {
public fun <init> ()V
public fun createContextual (Lcom/fasterxml/jackson/databind/DeserializationContext;Lcom/fasterxml/jackson/databind/BeanProperty;)Lcom/fasterxml/jackson/databind/JsonDeserializer;
public fun deserialize (Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;)Larrow/core/Option;
public synthetic fun deserialize (Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Object;
public fun getEmptyAccessPattern ()Lcom/fasterxml/jackson/databind/util/AccessPattern;
public fun getEmptyValue (Lcom/fasterxml/jackson/databind/DeserializationContext;)Larrow/core/Option;
public synthetic fun getEmptyValue (Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Object;
public fun getNullAccessPattern ()Lcom/fasterxml/jackson/databind/util/AccessPattern;
public fun getNullValue (Lcom/fasterxml/jackson/databind/DeserializationContext;)Larrow/core/Option;
public synthetic fun getNullValue (Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Object;
}

public final class arrow/integrations/jackson/module/OptionModule : com/fasterxml/jackson/databind/module/SimpleModule {
public static final field INSTANCE Larrow/integrations/jackson/module/OptionModule;
public fun setupModule (Lcom/fasterxml/jackson/databind/Module$SetupContext;)V
}

public final class arrow/integrations/jackson/module/OptionSerializer : com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer {
public fun <init> (Larrow/integrations/jackson/module/OptionSerializer;Lcom/fasterxml/jackson/databind/BeanProperty;Lcom/fasterxml/jackson/databind/jsontype/TypeSerializer;Lcom/fasterxml/jackson/databind/JsonSerializer;Lcom/fasterxml/jackson/databind/util/NameTransformer;Ljava/lang/Object;Z)V
public fun <init> (Lcom/fasterxml/jackson/databind/type/ReferenceType;ZLcom/fasterxml/jackson/databind/jsontype/TypeSerializer;Lcom/fasterxml/jackson/databind/JsonSerializer;)V
public synthetic fun _getReferenced (Ljava/lang/Object;)Ljava/lang/Object;
public synthetic fun _getReferencedIfPresent (Ljava/lang/Object;)Ljava/lang/Object;
public synthetic fun _isValuePresent (Ljava/lang/Object;)Z
public fun withContentInclusion (Ljava/lang/Object;Z)Lcom/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer;
}

public final class arrow/integrations/jackson/module/OptionSerializerResolver : com/fasterxml/jackson/databind/ser/Serializers$Base {
public static final field INSTANCE Larrow/integrations/jackson/module/OptionSerializerResolver;
public fun findReferenceSerializer (Lcom/fasterxml/jackson/databind/SerializationConfig;Lcom/fasterxml/jackson/databind/type/ReferenceType;Lcom/fasterxml/jackson/databind/BeanDescription;Lcom/fasterxml/jackson/databind/jsontype/TypeSerializer;Lcom/fasterxml/jackson/databind/JsonSerializer;)Lcom/fasterxml/jackson/databind/JsonSerializer;
}

public final class arrow/integrations/jackson/module/OptionTypeModifier : com/fasterxml/jackson/databind/type/TypeModifier {
public static final field INSTANCE Larrow/integrations/jackson/module/OptionTypeModifier;
public fun modifyType (Lcom/fasterxml/jackson/databind/JavaType;Ljava/lang/reflect/Type;Lcom/fasterxml/jackson/databind/type/TypeBindings;Lcom/fasterxml/jackson/databind/type/TypeFactory;)Lcom/fasterxml/jackson/databind/JavaType;
}

public final class arrow/integrations/jackson/module/internal/ElementDeserializer {
public static final field Companion Larrow/integrations/jackson/module/internal/ElementDeserializer$Companion;
public fun <init> (Larrow/core/Option;Larrow/core/Option;)V
public final fun component1 ()Larrow/core/Option;
public final fun component2 ()Larrow/core/Option;
public final fun copy (Larrow/core/Option;Larrow/core/Option;)Larrow/integrations/jackson/module/internal/ElementDeserializer;
public static synthetic fun copy$default (Larrow/integrations/jackson/module/internal/ElementDeserializer;Larrow/core/Option;Larrow/core/Option;ILjava/lang/Object;)Larrow/integrations/jackson/module/internal/ElementDeserializer;
public final fun deserialize (Lcom/fasterxml/jackson/databind/JavaType;Lcom/fasterxml/jackson/core/JsonToken;Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Object;
public fun equals (Ljava/lang/Object;)Z
public final fun getDeserializer ()Larrow/core/Option;
public final fun getTypeDeserializer ()Larrow/core/Option;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class arrow/integrations/jackson/module/internal/ElementDeserializer$Companion {
public final fun resolve (Lcom/fasterxml/jackson/databind/JavaType;Lcom/fasterxml/jackson/databind/DeserializationContext;Lcom/fasterxml/jackson/databind/BeanProperty;)Larrow/integrations/jackson/module/internal/ElementDeserializer;
}

public final class arrow/integrations/jackson/module/internal/ProductTypeDeserializer : com/fasterxml/jackson/databind/deser/std/StdDeserializer, com/fasterxml/jackson/databind/deser/ContextualDeserializer {
public fun <init> (Ljava/lang/Class;Lcom/fasterxml/jackson/databind/JavaType;Ljava/util/List;Lkotlin/jvm/functions/Function1;)V
public fun createContextual (Lcom/fasterxml/jackson/databind/DeserializationContext;Lcom/fasterxml/jackson/databind/BeanProperty;)Lcom/fasterxml/jackson/databind/JsonDeserializer;
public fun deserialize (Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Object;
}

public final class arrow/integrations/jackson/module/internal/ProductTypeDeserializer$InjectField {
public fun <init> (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public final fun getFieldName ()Ljava/lang/String;
public final fun getPoint ()Lkotlin/jvm/functions/Function1;
}

public final class arrow/integrations/jackson/module/internal/ProductTypeSerializer : com/fasterxml/jackson/databind/ser/std/StdSerializer {
public fun <init> (Ljava/lang/Class;Ljava/util/List;)V
public fun serialize (Ljava/lang/Object;Lcom/fasterxml/jackson/core/JsonGenerator;Lcom/fasterxml/jackson/databind/SerializerProvider;)V
}

public final class arrow/integrations/jackson/module/internal/ProductTypeSerializer$ProjectField {
public fun <init> (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public final fun getFieldName ()Ljava/lang/String;
public final fun getGetOption ()Lkotlin/jvm/functions/Function1;
}

public final class arrow/integrations/jackson/module/internal/UnionTypeDeserializer : com/fasterxml/jackson/databind/deser/std/StdDeserializer, com/fasterxml/jackson/databind/deser/ContextualDeserializer {
public fun <init> (Ljava/lang/Class;Lcom/fasterxml/jackson/databind/JavaType;Ljava/util/List;)V
public fun createContextual (Lcom/fasterxml/jackson/databind/DeserializationContext;Lcom/fasterxml/jackson/databind/BeanProperty;)Lcom/fasterxml/jackson/databind/JsonDeserializer;
public fun deserialize (Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Object;
}

public final class arrow/integrations/jackson/module/internal/UnionTypeDeserializer$InjectField {
public fun <init> (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public final fun getFieldName ()Ljava/lang/String;
public final fun getPoint ()Lkotlin/jvm/functions/Function1;
}

public final class arrow/integrations/jackson/module/internal/UnionTypeSerializer : com/fasterxml/jackson/databind/ser/std/StdSerializer {
public fun <init> (Ljava/lang/Class;Ljava/util/List;)V
public fun serialize (Ljava/lang/Object;Lcom/fasterxml/jackson/core/JsonGenerator;Lcom/fasterxml/jackson/databind/SerializerProvider;)V
}

public final class arrow/integrations/jackson/module/internal/UnionTypeSerializer$ProjectField {
public fun <init> (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public final fun getFieldName ()Ljava/lang/String;
public final fun getGetOption ()Lkotlin/jvm/functions/Function1;
}

33 changes: 33 additions & 0 deletions arrow-libs/integrations/arrow-core-jackson/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@file:Suppress("DSL_SCOPE_VIOLATION")

plugins {
id(libs.plugins.kotlin.jvm.get().pluginId)
id("arrow.kotlin")
alias(libs.plugins.publish)
alias(libs.plugins.kotlinx.serialization) // Needed for testing only
alias(libs.plugins.kotlinx.kover)
alias(libs.plugins.spotless)
alias(libs.plugins.dokka)
}

spotless {
kotlin {
ktlint().editorConfigOverride(mapOf("ktlint_standard_filename" to "disabled"))
}
}

apply(from = property("ANIMALSNIFFER"))

dependencies {
api(projects.arrowCore)
implementation(libs.jacksonModuleKotlin)
testImplementation(libs.kotlin.test)
testImplementation(libs.coroutines.test)
testImplementation(libs.kotest.property)
}

tasks.jar {
manifest {
attributes["Automatic-Module-Name"] = "arrow.core.jackson"
}
}
2 changes: 2 additions & 0 deletions arrow-libs/integrations/arrow-core-jackson/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Maven publishing configuration
POM_NAME=Arrow-Core-Jackson
5 changes: 5 additions & 0 deletions arrow-libs/integrations/arrow-core-jackson/knit.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
knit.package=arrow.integrations.jackson.examples
knit.dir=src/test/kotlin/examples/

test.package=arrow.integrations.jackson.examples.test
test.dir=src/test/kotlin/examples/autogenerated/
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package arrow.integrations.jackson.module

import com.fasterxml.jackson.databind.ObjectMapper

public fun ObjectMapper.registerArrowModule(
eitherModuleConfig: EitherModuleConfig = EitherModuleConfig("left", "right"),
iorModuleConfig: IorModuleConfig = IorModuleConfig("left", "right"),
): ObjectMapper =
registerModules(
// no longer required, as they are value classes
// NonEmptyListModule,
// NonEmptySetModule,
OptionModule,
EitherModule(eitherModuleConfig.leftFieldName, eitherModuleConfig.rightFieldName),
IorModule(iorModuleConfig.leftFieldName, iorModuleConfig.rightFieldName),
)

public data class EitherModuleConfig(val leftFieldName: String, val rightFieldName: String)

public data class IorModuleConfig(val leftFieldName: String, val rightFieldName: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package arrow.integrations.jackson.module

import arrow.core.Either
import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.left
import arrow.core.right
import arrow.integrations.jackson.module.internal.UnionTypeDeserializer
import arrow.integrations.jackson.module.internal.UnionTypeSerializer
import com.fasterxml.jackson.core.json.PackageVersion
import com.fasterxml.jackson.databind.BeanDescription
import com.fasterxml.jackson.databind.DeserializationConfig
import com.fasterxml.jackson.databind.JavaType
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonSerializer
import com.fasterxml.jackson.databind.SerializationConfig
import com.fasterxml.jackson.databind.deser.Deserializers
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.ser.Serializers

public class EitherModule(private val leftFieldName: String, private val rightFieldName: String) :
SimpleModule(EitherModule::class.java.canonicalName, PackageVersion.VERSION) {
override fun setupModule(context: SetupContext) {
super.setupModule(context)
context.addDeserializers(EitherDeserializerResolver(leftFieldName, rightFieldName))
context.addSerializers(EitherSerializerResolver(leftFieldName, rightFieldName))
}
}

public class EitherSerializerResolver(leftFieldName: String, rightFieldName: String) :
Serializers.Base() {
private val serializer =
UnionTypeSerializer(
Either::class.java,
listOf(
UnionTypeSerializer.ProjectField(leftFieldName) { either -> either.swap().orNone() },
UnionTypeSerializer.ProjectField(rightFieldName) { either -> either.orNone() },
),
)

override fun findSerializer(
config: SerializationConfig,
javaType: JavaType,
beanDesc: BeanDescription?,
): JsonSerializer<*>? =
when {
Either::class.java.isAssignableFrom(javaType.rawClass) -> serializer
else -> null
}
}

private fun <E, A> Either<E, A>.orNone(): Option<A> = fold({ None }, ::Some)

public class EitherDeserializerResolver(
private val leftFieldName: String,
private val rightFieldName: String,
) : Deserializers.Base() {
override fun findBeanDeserializer(
type: JavaType,
config: DeserializationConfig,
beanDesc: BeanDescription?,
): JsonDeserializer<*>? =
when {
Either::class.java.isAssignableFrom(type.rawClass) ->
UnionTypeDeserializer(
Either::class.java,
type,
listOf(
UnionTypeDeserializer.InjectField(leftFieldName) { leftValue -> leftValue.left() },
UnionTypeDeserializer.InjectField(rightFieldName) { rightValue -> rightValue.right() },
),
)
else -> null
}
}
Loading

0 comments on commit 392eff6

Please sign in to comment.