Handler Method

public Mono<ServerResponse> query(ServerRequest request){
        Flux<User> share = Flux.interval(Duration.ofSeconds(1))
                .onBackpressureDrop()
                .map(user -> new User().setAge(random.nextInt()).setName("李四").setInstant(Instant.now())).share();
        return ServerResponse
                .ok()
                .contentType(MediaType.APPLICATION_NDJSON)
                .body(share,User.class);

Router Response Method

    @Bean
    public RouterFunction<ServerResponse> hello(UserHandler userHandler) {
        return RouterFunctions
                .route(RequestPredicates
                                .GET("/query")
                                .and(RequestPredicates.accept(MediaType.APPLICATION_NDJSON)),
                        userHandler::query);
    }

This return will cause Chinese garbled! How to solve it?

Comment From: wilkinsona

How have you identified that the response is garbled? Without knowing how the GET request to /query is being made, I can't be certain where the problem might be. It could be that the server is producing the correct data and the client is not handling it correctly, or it could be that the response is corrupted before it leaves the server. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: zhengdewei94

I am glad to hear from you, here is an example:  https://github.com/zhengdewei94/spring-boot-webflux-demo.git

------------------ 原始邮件 ------------------ 发件人: "spring-projects/spring-boot" <notifications@github.com>; 发送时间: 2021年1月19日(星期二) 下午5:18 收件人: "spring-projects/spring-boot"<spring-boot@noreply.github.com>; 抄送: "山水之间"<948493961@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [spring-projects/spring-boot] Use WebFlux Chinese response encoding problem (#24881)

How have you identified that the response is garbled? Without knowing how the GET request to /query is being made, I can't be certain where the problem might be. It could be that the server is producing the correct data and the client is not handling it correctly, or it could be that the response is corrupted before it leaves the server. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Comment From: wilkinsona

Thanks for the sample. Unfortunately, it doesn't reproduce the problem:

$ curl http://localhost:8080/query -i -H "Accept: application/x-ndjson"
HTTP/1.1 200 OK
transfer-encoding: chunked
Content-Type: application/x-ndjson

{"name":"李四","instant":"2021-01-19T09:49:59.328Z"}
{"name":"李四","instant":"2021-01-19T09:50:00.329Z"}
{"name":"李四","instant":"2021-01-19T09:50:01.329Z"}
{"name":"李四","instant":"2021-01-19T09:50:02.327Z"}
{"name":"李四","instant":"2021-01-19T09:50:03.329Z"}
{"name":"李四","instant":"2021-01-19T09:50:04.330Z"}
{"name":"李四","instant":"2021-01-19T09:50:05.329Z"}
{"name":"李四","instant":"2021-01-19T09:50:06.331Z"}

Comment From: zhengdewei94

Thank you very much, I found the reason is a problem with the idea terminal! thank you very much!

------------------ 原始邮件 ------------------ 发件人: "spring-projects/spring-boot" <notifications@github.com>; 发送时间: 2021年1月19日(星期二) 下午5:52 收件人: "spring-projects/spring-boot"<spring-boot@noreply.github.com>; 抄送: "山水之间"<948493961@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [spring-projects/spring-boot] Use WebFlux Chinese response encoding problem (#24881)

Thanks for the sample. Unfortunately, it doesn't reproduce the problem: $ curl http://localhost:8080/query -i -H "Accept: application/x-ndjson" HTTP/1.1 200 OK transfer-encoding: chunked Content-Type: application/x-ndjson {"name":"李四","instant":"2021-01-19T09:49:59.328Z"} {"name":"李四","instant":"2021-01-19T09:50:00.329Z"} {"name":"李四","instant":"2021-01-19T09:50:01.329Z"} {"name":"李四","instant":"2021-01-19T09:50:02.327Z"} {"name":"李四","instant":"2021-01-19T09:50:03.329Z"} {"name":"李四","instant":"2021-01-19T09:50:04.330Z"} {"name":"李四","instant":"2021-01-19T09:50:05.329Z"} {"name":"李四","instant":"2021-01-19T09:50:06.331Z"}
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.