commit 8504d6f1c4f4738dcb749fdec28f4abe55f78214
parent fab842d4ee745913b6074f24d682efd0a44cbe54
Author: MS <ms@taler.net>
Date: Tue, 7 Jun 2022 18:04:45 +0200
fix JSON content negotiation
Diffstat:
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
@@ -140,4 +140,10 @@ data class NewTransactionReq(
val paytoUri: String,
// $currency:X.Y format
val amount: String?
+)
+
+data class SandboxConfig(
+ val currency: String,
+ val version: String,
+ val name: String
)
\ No newline at end of file
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -456,6 +456,15 @@ suspend inline fun <reified T : Any> ApplicationCall.receiveJson(): T {
}
val singleThreadContext = newSingleThreadContext("DB")
+fun setJsonHandler(ctx: ObjectMapper) {
+ ctx.enable(SerializationFeature.INDENT_OUTPUT)
+ ctx.setDefaultPrettyPrinter(DefaultPrettyPrinter().apply {
+ indentArraysWith(DefaultPrettyPrinter.FixedSpaceIndenter.instance)
+ indentObjectsWith(DefaultIndenter(" ", "\n"))
+ })
+ ctx.registerModule(KotlinModule(nullisSameAsDefault = true))
+}
+
val sandboxApp: Application.() -> Unit = {
install(CallLogging) {
this.level = org.slf4j.event.Level.DEBUG
@@ -478,17 +487,11 @@ val sandboxApp: Application.() -> Unit = {
* "xml" and the request made gets somehow assigned the
* "text/plain" type: */
register(ContentType.Text.Plain, XMLEbicsConverter())
+ jackson(contentType = ContentType.Application.Json) { setJsonHandler(this) }
/**
* Make jackson the default parser. It runs also when
* the Content-Type request header is missing. */
- jackson(contentType = ContentType.Any) {
- enable(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT)
- setDefaultPrettyPrinter(DefaultPrettyPrinter().apply {
- indentArraysWith(DefaultPrettyPrinter.FixedSpaceIndenter.instance)
- indentObjectsWith(DefaultIndenter(" ", "\n"))
- })
- registerModule(KotlinModule(nullisSameAsDefault = true))
- }
+ jackson(contentType = ContentType.Any) { setJsonHandler(this) }
}
install(StatusPages) {
exception<ArithmeticException> { cause ->
@@ -1105,12 +1108,11 @@ val sandboxApp: Application.() -> Unit = {
route("/integration-api") {
get("/config") {
val demobank = ensureDemobank(call)
- call.respond(object {
- val name = "taler-bank-integration"
- // FIXME: avoid hard-coding the version!
- val version = "0:0:0"
- val currency = demobank.currency
- })
+ call.respond(SandboxConfig(
+ name = "taler-bank-integration",
+ version = "0:0:0",
+ currency = demobank.currency
+ ))
return@get
}
post("/withdrawal-operation/{wopid}") {