Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-15685

ClientResponse bodyToFlux fails when encoding empty JSON array

    XMLWordPrintable

    Details

      Description

      When the web client receives an empty array JSON as response a MismatchedInputException occurs.

      In the following project https://github.com/gilbertojrequena/web-reactive-test you can find the example code.

      Here the falling test https://github.com/gilbertojrequena/web-reactive-test/blob/master/src/test/java/com/gilbertojrequena/reactive/service/FooServiceTest.java#L37

      org.springframework.core.codec.DecodingException: JSON decoding error: No content to map due to end-of-input; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
       at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 0]))
      
      	at reactor.test.DefaultStepVerifierBuilder.failPrefix(DefaultStepVerifierBuilder.java:2114)
      	at reactor.test.DefaultStepVerifierBuilder.fail(DefaultStepVerifierBuilder.java:2110)
      	at reactor.test.DefaultStepVerifierBuilder.lambda$expectComplete$3(DefaultStepVerifierBuilder.java:199)
      	at reactor.test.DefaultStepVerifierBuilder$SignalEvent.test(DefaultStepVerifierBuilder.java:1855)
      	at reactor.test.DefaultStepVerifierBuilder$DefaultVerifySubscriber.onSignal(DefaultStepVerifierBuilder.java:1241)
      	at reactor.test.DefaultStepVerifierBuilder$DefaultVerifySubscriber.onExpectation(DefaultStepVerifierBuilder.java:1186)
      	at reactor.test.DefaultStepVerifierBuilder$DefaultVerifySubscriber.onError(DefaultStepVerifierBuilder.java:858)
      	at reactor.core.publisher.MonoFlatMapMany$FlatMapInner.onError(MonoFlatMapMany.java:234)
      	at reactor.core.publisher.FluxMap$MapSubscriber.onError(FluxMap.java:120)
      	at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:104)
      	at reactor.core.publisher.FluxFlatMap$FlatMapMain.drainLoop(FluxFlatMap.java:608)
      	at reactor.core.publisher.FluxFlatMap$FlatMapMain.drain(FluxFlatMap.java:487)
      	at reactor.core.publisher.FluxFlatMap$FlatMapInner.onSubscribe(FluxFlatMap.java:896)
      	at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:89)
      	at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:54)
      	at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:380)
      	at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:108)
      	at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:108)
      	at reactor.ipc.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:207)
      	at reactor.ipc.netty.channel.FluxReceive.onInboundNext(FluxReceive.java:322)
      	at reactor.ipc.netty.channel.ChannelOperations.onInboundNext(ChannelOperations.java:316)
      	at reactor.ipc.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:581)
      	at reactor.ipc.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:125)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
      	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
      	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
      	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:297)
      	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:413)
      	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
      	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
      	at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:241)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
      	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
      	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
      	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
      	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
      	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
      	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
      	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
      	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
      	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
      	at java.lang.Thread.run(Thread.java:748)
      	Suppressed: org.springframework.core.codec.DecodingException: JSON decoding error: No content to map due to end-of-input; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
       at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 0]
      		at org.springframework.http.codec.json.Jackson2JsonDecoder.lambda$decodeInternal$0(Jackson2JsonDecoder.java:124)
      		at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:100)
      		... 38 more
      	Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
       at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 0]
      		at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:58)
      		at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1320)
      		at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:356)
      		at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1598)
      		at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1183)
      		at org.springframework.http.codec.json.Jackson2JsonDecoder.lambda$decodeInternal$0(Jackson2JsonDecoder.java:116)
      		... 39 more
      

        Attachments

          Activity

            People

            Assignee:
            arjen.poutsma Arjen Poutsma
            Reporter:
            gilbertojrequena Gilberto J Requena
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 45 weeks, 4 days ago