[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 02/02: use jackson
From: |
gnunet |
Subject: |
[libeufin] 02/02: use jackson |
Date: |
Wed, 20 May 2020 13:21:53 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository libeufin.
commit 9c36aa1839fd0279d5b045b28ae9313bfbf81c39
Author: Florian Dold <address@hidden>
AuthorDate: Wed May 20 16:51:43 2020 +0530
use jackson
---
integration-tests/test-ebics.py | 2 +-
nexus/build.gradle | 2 +-
.../src/main/kotlin/tech/libeufin/nexus/Helpers.kt | 11 ++++----
nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 31 +++++++++++-----------
util/build.gradle | 2 --
5 files changed, 23 insertions(+), 25 deletions(-)
diff --git a/integration-tests/test-ebics.py b/integration-tests/test-ebics.py
index d640e4a..ac633aa 100755
--- a/integration-tests/test-ebics.py
+++ b/integration-tests/test-ebics.py
@@ -231,7 +231,7 @@ assertResponse(
assertResponse(
post(
"http://localhost:5001/bank-accounts/collected-transactions",
- json=dict(type="ebics", name="my-ebics"),
+ json=dict(transport=dict(type="ebics", name="my-ebics")),
headers=dict(Authorization=USER_AUTHORIZATION_HEADER),
)
)
diff --git a/nexus/build.gradle b/nexus/build.gradle
index 13017b4..b109726 100644
--- a/nexus/build.gradle
+++ b/nexus/build.gradle
@@ -76,9 +76,9 @@ dependencies {
implementation "io.ktor:ktor-server-core:$ktor_version"
implementation "io.ktor:ktor-client-apache:$ktor_version"
- implementation "io.ktor:ktor-gson:$ktor_version"
implementation "io.ktor:ktor-server-netty:$ktor_version"
implementation "io.ktor:ktor-auth:$ktor_version"
+ implementation "io.ktor:ktor-jackson:$ktor_version"
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
index 6258679..5967af0 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -1,7 +1,8 @@
package tech.libeufin.nexus
-import com.google.gson.Gson
-import com.google.gson.JsonObject
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
+import com.fasterxml.jackson.module.kotlin.treeToValue
import io.ktor.client.HttpClient
import io.ktor.http.HttpStatusCode
import org.jetbrains.exposed.sql.and
@@ -57,10 +58,8 @@ fun extractFirstBic(bankCodes:
List<EbicsTypes.AbstractBankCode>?): String? {
return null
}
-fun getTransportFromJsonObject(jo: JsonObject): Transport {
- return Gson().fromJson(
- expectNonNull(jo.get("transport")).asJsonObject, Transport::class.java
- )
+fun getTransportFromJsonObject(jo: JsonNode): Transport {
+ return jacksonObjectMapper().treeToValue(jo.get("transport"),
Transport::class.java)
}
/**
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index e57193b..ea7a91c 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -19,22 +19,25 @@
package tech.libeufin.nexus
+import com.fasterxml.jackson.core.util.DefaultIndenter
+import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.SerializationFeature
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.ProgramResult
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.prompt
-import com.google.gson.Gson
-import com.google.gson.JsonObject
import io.ktor.application.ApplicationCallPipeline
import io.ktor.application.call
import io.ktor.application.install
import io.ktor.client.HttpClient
import io.ktor.features.*
-import io.ktor.gson.gson
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
+import io.ktor.jackson.jackson
import io.ktor.request.ApplicationReceivePipeline
import io.ktor.request.ApplicationReceiveRequest
import io.ktor.request.receive
@@ -218,9 +221,13 @@ fun serverMain() {
this.logger = tech.libeufin.nexus.logger
}
install(ContentNegotiation) {
- gson {
- setDateFormat(DateFormat.LONG)
- setPrettyPrinting()
+ jackson {
+ enable(SerializationFeature.INDENT_OUTPUT)
+ setDefaultPrettyPrinter(DefaultPrettyPrinter().apply {
+
indentArraysWith(DefaultPrettyPrinter.FixedSpaceIndenter.instance)
+ indentObjectsWith(DefaultIndenter(" ", "\n"))
+ })
+ //registerModule(JavaTimeModule())
}
}
install(StatusPages) {
@@ -516,15 +523,12 @@ fun serverMain() {
post("/bank-transports") {
val userId = transaction {
authenticateRequest(call.request.headers["Authorization"]).id.value }
// user exists and is authenticated.
- val body = call.receive<JsonObject>()
+ val body = call.receive<JsonNode>()
val transport: Transport = getTransportFromJsonObject(body)
when (transport.type) {
"ebics" -> {
if (body.get("backup") != null) {
- val backup = Gson().fromJson(
- body.get("backup").asJsonObject,
- EbicsKeysBackupJson::class.java
- )
+ val backup =
jacksonObjectMapper().treeToValue(body,EbicsKeysBackupJson::class.java)
val (authKey, encKey, sigKey) = try {
Triple(
CryptoUtil.decryptKey(
@@ -574,10 +578,7 @@ fun serverMain() {
return@post
}
if (body.get("data") != null) {
- val data = Gson().fromJson(
- body.get("data"),
- EbicsNewTransport::class.java
- )
+ val data =
jacksonObjectMapper().treeToValue((body.get("data")),
EbicsNewTransport::class.java)
val pairA = CryptoUtil.generateRsaKeyPair(2048)
val pairB = CryptoUtil.generateRsaKeyPair(2048)
val pairC = CryptoUtil.generateRsaKeyPair(2048)
diff --git a/util/build.gradle b/util/build.gradle
index c53b544..d06ff1b 100644
--- a/util/build.gradle
+++ b/util/build.gradle
@@ -28,8 +28,6 @@ sourceSets {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
- implementation "io.ktor:ktor-gson:1.1.5"
- implementation group: 'io.ktor', name: 'ktor-gson', version: '0.9.0'
implementation "org.jetbrains.exposed:exposed:0.17.6"
implementation "io.ktor:ktor-server-netty:1.2.4"
implementation "ch.qos.logback:logback-classic:1.2.3"
--
To stop receiving notification emails like this one, please contact
address@hidden.