Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockEngine 'Invalid JSON at 4088: Unexpected end in string' on iOS #38

Closed
jrocharodrigues opened this issue Feb 7, 2019 · 2 comments
Closed

Comments

@jrocharodrigues
Copy link

jrocharodrigues commented Feb 7, 2019

Ktor Version

1.1.2

###Kx.io Version
0.1.5-dev-4

Ktor Engine Used(client or server and name)

Ktor-client with MockEngine

JVM Version, Operating System and Relevant Context

The bug occurs in when running my project on iOS in a multi-platform (android/iOS) project.
In Android it works as expected

Feedback

I've recently came across this bug Kotlin/kotlinx.serialization#360 . After upgrading both kotlinx-io and kotlinx-coroutines-io to version 0.1.5-dev-4 the issue no long occured when making live requests to server.
But when i use the mock engine, with an content bigger than 4088 chars i got this error:
Invalid JSON at 4088: Unexpected end in string

If my content is smaller than 4088 it works fine.

Here's the code i use to create the MockEngin

val TOPOLOGY_ANSWER = """
  VERY BIG JSON STRING
"""

val httpMockEngine =  MockEngine {
        when (url.toString()) {
            "$baseUrl/${ApiEndpoints.TOPOLOGY}" -> {
                MockHttpResponse(
                    call,
                    HttpStatusCode.OK,                   
                    ByteReadChannel(TOPOLOGY_ANSWER.toByteArray(Charsets.UTF_8)),
                    headersOf("Content-Type" to listOf(ContentType.Application.Json.toString()))
                )
            }
            else -> {
                error("Unhandled $url")
            }
        }

val client: HttpClient = HttpClient(httpMockEngine) {
                install(JsonFeature) {
                    serializer = KotlinxSerializer(Json.nonstrict).apply {
                        setMapper(Topology::class, Topology.serializer())
                    }
                }

Thanks in advance

@jrocharodrigues
Copy link
Author

If you need more info, just let me know.

@fzhinkin
Copy link
Collaborator

We're rebooting the kotlinx-io development (see #131), all issues related to the previous versions will be closed. Consider reopening it if the issue remains (or the feature is still missing) in a new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants