mirror of
https://github.com/corda/corda.git
synced 2025-04-07 11:27:01 +00:00
Fixed issues with incorrect serialisation in test utilities.
This commit is contained in:
parent
d1c9cabd18
commit
234ffb141c
@ -32,12 +32,6 @@ object JsonSupport {
|
||||
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
|
||||
mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
|
||||
|
||||
val timeModule = SimpleModule("java.time")
|
||||
timeModule.addSerializer(LocalDate::class.java, ToStringSerializer)
|
||||
timeModule.addDeserializer(LocalDate::class.java, LocalDateDeserializer)
|
||||
timeModule.addKeyDeserializer(LocalDate::class.java, LocalDateKeyDeserializer)
|
||||
timeModule.addSerializer(LocalDateTime::class.java, ToStringSerializer)
|
||||
|
||||
val cordaModule = SimpleModule("core")
|
||||
cordaModule.addSerializer(Party::class.java, PartySerializer)
|
||||
cordaModule.addDeserializer(Party::class.java, PartyDeserializer)
|
||||
@ -62,12 +56,23 @@ object JsonSupport {
|
||||
cordaModule.addSerializer(NodeInfo::class.java, NodeInfoSerializer)
|
||||
cordaModule.addDeserializer(NodeInfo::class.java, NodeInfoDeserializer)
|
||||
|
||||
mapper.registerModule(timeModule)
|
||||
mapper.registerModule(createJavaTimeModule())
|
||||
mapper.registerModule(cordaModule)
|
||||
mapper.registerModule(KotlinModule())
|
||||
return mapper
|
||||
}
|
||||
|
||||
fun createJavaTimeModule(): Module {
|
||||
val timeModule = SimpleModule("java.time")
|
||||
timeModule.apply {
|
||||
addSerializer(LocalDate::class.java, ToStringSerializer)
|
||||
addDeserializer(LocalDate::class.java, LocalDateDeserializer)
|
||||
addKeyDeserializer(LocalDate::class.java, LocalDateKeyDeserializer)
|
||||
addSerializer(LocalDateTime::class.java, ToStringSerializer)
|
||||
}
|
||||
return timeModule
|
||||
}
|
||||
|
||||
class ServiceHubObjectMapper(val identities: IdentityService) : ObjectMapper()
|
||||
|
||||
object ToStringSerializer : JsonSerializer<Any>() {
|
||||
|
@ -23,7 +23,7 @@ class HttpApi(val root: URL) {
|
||||
*/
|
||||
inline fun<reified T: Any> getJson(path: String, params: Map<String, String> = mapOf()) = HttpUtils.getJson<T>(URL(root, path), params)
|
||||
|
||||
private fun toJson(any: Any) = any as? String ?: ObjectMapper().writeValueAsString(any)
|
||||
private fun toJson(any: Any) = any as? String ?: HttpUtils.createDefaultMapper().writeValueAsString(any)
|
||||
|
||||
companion object {
|
||||
fun fromHostAndPort(hostAndPort: HostAndPort, base: String, protocol: String = "http"): HttpApi
|
||||
|
@ -3,6 +3,7 @@ package net.corda.testing.http
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.node.utilities.JsonSupport
|
||||
import okhttp3.*
|
||||
import java.net.URL
|
||||
import java.util.concurrent.TimeUnit
|
||||
@ -31,7 +32,7 @@ object HttpUtils {
|
||||
inline fun<reified T: Any> getJson(url: URL, params: Map<String, String> = mapOf()) : T {
|
||||
val paramString = if(params.isEmpty()) "" else "?" + params.map { "${it.key}=${it.value}" }.joinToString("&")
|
||||
val parameterisedUrl = URL(url.toExternalForm() + paramString)
|
||||
return ObjectMapper().registerModule(KotlinModule()).readValue(parameterisedUrl, T::class.java)
|
||||
return createDefaultMapper().readValue(parameterisedUrl, T::class.java)
|
||||
}
|
||||
|
||||
private fun makeRequest(request: Request): Boolean {
|
||||
@ -44,14 +45,7 @@ object HttpUtils {
|
||||
return response.isSuccessful
|
||||
}
|
||||
|
||||
private fun getRequest(request: Request): Pair<Boolean, String> {
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
if (!response.isSuccessful) {
|
||||
logger.error("Could not fulfill HTTP request of type ${request.method()} to ${request.url()}. Status Code: ${response.code()}. Message: ${response.body().string()}")
|
||||
return Pair(false, "")
|
||||
}
|
||||
|
||||
return Pair(true, response.body().string())
|
||||
fun createDefaultMapper(): ObjectMapper {
|
||||
return ObjectMapper().registerModule(JsonSupport.createJavaTimeModule()).registerModule(KotlinModule())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user