Search code examples
jsonspringspring-bootkotlinconcordion

HttpMessageNotReadableException: JSON parse error


Here is my class which I'm trying to use:

data class GetAppResponse(
        val externalId: Long?,
        val lastUpdate: LocalDateTime?,
        var connectionInfo: ConnectionInfoDto? = null
) : BaseResponse()

data class ConnectionInfoDto(
        val catalogUrl: String?,
        val catalogPass: String?,
        val catalogLogin: String?
)

When I'm trying to serialize it to json:

fun partner() {
        partner.stubFor(get(anyUrl())
                .willReturn(aResponse()
                        .withHeader("Content-Type", "application/json")
                        .withBody("{\"externalId\": 1, " +
                                "\"lastUpdate\": \"2020-01-01T10:00:00\", " +
                                "\"connectionInfo\": {" +
                                "\"catalogUrl\": " + archiveUrl + ", " +
                                "\"catalogPass\": \"user\", " +
                                "\"catalogLogin\": \"user\"}")
                ))
    }

I'm getting

 nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized token 'http': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unrecognized token 'http': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
     at [Source: (PushbackInputStream); line: 1, column: 94] (through reference chain: GetAppResponse["connectionInfo"])

What is a reason and how to solve the problem?


Solution

  • Replace:

    "\"catalogUrl\": " + archiveUrl + ", " +
    

    with this:

    "\"catalogUrl\": \"" + archiveUrl + "\", " +