spring-rsocket-kotlin协同程序流:com.fasterxml.jackson.databind.jsonmappingexception

cig3rfwq  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(281)

当我将流作为@payload传递,将元数据作为@destinationvariable传递时,我能够使用spring和rsocket将流从服务a发送到服务b,如下所示:

// THIS CODE WORKS...

    // SERVICE-A
    rSocketRequester
    .route("v1.blob.upload.{metadata}", UploadRequest("filename.mp4"))
    .data(flowData)
    .........

    // SERVICE-B
    @MessageMapping("v1.blob.upload.{metadata}")
    suspend fun upload(
        @Payload payload: Flow<DataBuffer>,
        @DestinationVariable metadata: UploadRequest
    ): Flow<UploadResponse>

当我试图传递一个包含流和元数据的对象时,我从jackson那里得到了一个序列化错误(请参阅本文底部的异常)。
有没有可能做到以下几点?这将非常好,因为通过rest调用发送的请求可以用于rsocket调用。我很感激你的帮助,以确定是否有可能和我需要做什么。。。至少,我怀疑是自定义json序列化程序,但这只是猜测。
谢谢你的帮助和时间!

// THIS CODE FAILS...

    // SERVICE-A
    rSocketRequester
    .route("v1.blob.upload")
    .data(UploadRequest(flowData, "filename.mp4")
    .........

    // SERVICE-B
    @MessageMapping("v1.blob.upload")
    suspend fun upload(
        @Payload payload: UploadRequest
    ): Flow<UploadResponse>
// THE EXCEPTION...

org.springframework.core.codec.EncodingException:**JSON encoding error:**(was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.ingios.csc.services.run.UploadRequest["data"]->kotlinx.coroutines.reactive.PublisherAsFlow["collectToFun$kotlinx_coroutines_core"]->kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1["context"])
    at org.springframework.http.codec.json.AbstractJackson2Encoder.encodeValue(AbstractJackson2Encoder.java:229) ~[spring-web-5.3.5.jar:5.3.5]
    at org.springframework.messaging.rsocket.DefaultRSocketRequester$DefaultRequestSpec.encodeData(DefaultRSocketRequester.java:245) ~[spring-messaging-5.3.5.jar:5.3.5]
    at org.springframework.messaging.rsocket.DefaultRSocketRequester$DefaultRequestSpec.lambda$createPayload$0(DefaultRSocketRequester.java:199) ~[spring-messaging-5.3.5.jar:5.3.5]
    at reactor.core.publisher.MonoCallable.subscribe(MonoCallable.java:56) ~[reactor-core-3.4.4.jar:3.4.4]
    at reactor.core.publisher.Mono.subscribe(Mono.java:4099) ~[reactor-core-3.4.4.jar:3.4.4]
    at reactor.core.publisher.MonoZip.subscribe(MonoZip.java:128) ~[reactor-core-3.4.4.jar:3.4.4]
    at reactor.core.publisher.Flux.subscribe(Flux.java:8185) ~[reactor-core-3.4.4.jar:3.4.4]
    at kotlinx.coroutines.reactive.PublisherAsFlow.collectImpl(ReactiveFlow.kt:93) ~[kotlinx-coroutines-reactive-1.4.3.jar:na]
    at kotlinx.coroutines.reactive.PublisherAsFlow.collect(ReactiveFlow.kt:78) ~[kotlinx-coroutines-reactive-1.4.3.jar:na]
    at com.ingios.csc.services.run.RunApplication$Consumer$consume$1.invokeSuspend(RunApplication.kt:95) ~[main/:na]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-1.4.31.jar:1.4.31-release-344 (1.4.31)]
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) ~[kotlinx-coroutines-core-jvm-1.4.3.jar:na]
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274) ~[kotlinx-coroutines-core-jvm-1.4.3.jar:na]
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:84) ~[kotlinx-coroutines-core-jvm-1.4.3.jar:na]
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59) ~[kotlinx-coroutines-core-jvm-1.4.3.jar:na]
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source) ~[kotlinx-coroutines-core-jvm-1.4.3.jar:na]
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38) ~[kotlinx-coroutines-core-jvm-1.4.3.jar:na]
    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source) ~[kotlinx-coroutines-core-jvm-1.4.3.jar:na]
    at com.ingios.csc.services.run.RunApplication$Consumer.consume(RunApplication.kt:56) ~[main/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:344) ~[spring-context-5.3.5.jar:5.3.5]
    at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:229) ~[spring-context-5.3.5.jar:5.3.5]
    at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:166) ~[spring-context-5.3.5.jar:5.3.5]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.5.jar:5.3.5]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.5.jar:5.3.5]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.5.jar:5.3.5]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.5.jar:5.3.5]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.5.jar:5.3.5]
    at org.springframework.boot.context.event.EventPublishingRunListener.running(EventPublishingRunListener.java:111) ~[spring-boot-2.4.4.jar:2.4.4]
    at org.springframework.boot.SpringApplicationRunListeners.lambda$running$6(SpringApplicationRunListeners.java:79) ~[spring-boot-2.4.4.jar:2.4.4]
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) ~[na:na]
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117) ~[spring-boot-2.4.4.jar:2.4.4]
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111) ~[spring-boot-2.4.4.jar:2.4.4]
    at org.springframework.boot.SpringApplicationRunListeners.running(SpringApplicationRunListeners.java:79) ~[spring-boot-2.4.4.jar:2.4.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:341) ~[spring-boot-2.4.4.jar:2.4.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1313) ~[spring-boot-2.4.4.jar:2.4.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[spring-boot-2.4.4.jar:2.4.4]
    at com.ingios.csc.services.run.RunApplicationKt.main(RunApplication.kt:94) ~[main/:na]
Caused by: com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.ingios.csc.services.run.UploadRequest["data"]->kotlinx.coroutines.reactive.PublisherAsFlow["collectToFun$kotlinx_coroutines_core"]->kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1["context"])
    at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:397) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:356) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:763) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:755) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:755) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1516) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1006) ~[jackson-databind-2.11.4.jar:2.11.4]
    at org.springframework.http.codec.json.AbstractJackson2Encoder.encodeValue(AbstractJackson2Encoder.java:222) ~[spring-web-5.3.5.jar:5.3.5]
    ... 40 common frames omitted
Caused by: java.lang.NullPointerException: null
    at kotlin.coroutines.jvm.internal.ContinuationImpl.getContext(ContinuationImpl.kt:105) ~[kotlin-stdlib-1.4.31.jar:1.4.31-release-344 (1.4.31)]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:689) ~[jackson-databind-2.11.4.jar:2.11.4]
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:755) ~[jackson-databind-2.11.4.jar:2.11.4]
    ... 52 common frames omitted

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题