Closed refeccd closed 1 year ago
没看懂,请把问题再描述清楚一些
com.alibaba.fastjson2.writer.ObjectWriterProvider#getObjectWriter(java.lang.reflect.Type, java.lang.Class, boolean) 可能是被proxy导致的,你可以调试下这个的276行么?
这是一个最小复现的 demo 一旦注释掉 consumer/pom.xml#L22,就会触发异常
Caused by: org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: autoType not support input com.github.pagehelper.Page, offset 82
... 45 more
Caused by: com.alibaba.fastjson2.JSONException: autoType not support input com.github.pagehelper.Page, offset 82
at com.alibaba.fastjson2.reader.FieldReaderList.checkObjectAutoType(FieldReaderList.java:234)
at com.alibaba.fastjson2.reader.ORG_3_5_PageResult.readJSONBObject(Unknown Source)
at com.alibaba.fastjson2.JSONB.parseObject(JSONB.java:547)
at org.apache.dubbo.common.serialize.fastjson2.FastJson2ObjectInput.readObject(FastJson2ObjectInput.java:149)
at org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper$ProxyObjectInput.readObject(DefaultSerializationExceptionWrapper.java:175)
... 42 more
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.doReceived(DefaultFuture.java:249)
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:200)
at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:188)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleResponse(HeaderExchangeHandler.java:65)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:206)
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:53)
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:62)
at org.apache.dubbo.common.threadpool.ThreadlessExecutor$RunnableWrapper.run(ThreadlessExecutor.java:152)
at org.apache.dubbo.common.threadpool.ThreadlessExecutor.waitAndDrain(ThreadlessExecutor.java:77)
at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:205)
... 33 more
JSONB dump
{
"@type":"com.example.provider.api.entity.PageResult#0",
"@value":{
"list#1":{
"@type":"com.github.pagehelper.Page#2",
"@value":[
{
"@type":"com.example.provider.api.entity.User#3",
"@value":{
"id#4":1
}
},
{
"@type":"#3",
"@value":{
"#4":2
}
}
]
}
}
}
大致跟了下断点,由于Dubbo
写入时指定了WriteClassName
,所以需要写入typeName
代码位置:https://github.com/alibaba/fastjson2/blob/ba11876609adeb36c13bcf475a4e5ec90c085d61/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterImplList.java#L128-L135
所以最终写入的@type
就是com.github.pagehelper.Page
,由于 consumer 端没有依赖PageHelper
,导致反序列化失败
所以关于这块,有一点我的疑问是:
对于这种场景(泛指继承于父类从而保证在编译上不保错的情况),到底应该怎么处理呢?
类型判断这里,使用instanceOf
,会丢掉原始类型的一些字段信息,但是这个在某些情况(比如Rpc接口编程的时候)好像也说得过去?
这是一个好问题,我会和dubbo的同学沟通一个方案
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.36-SNAPSHOT/ @liaozan 问题已经修复,帮忙用2.0.36-SNAPSHOT版本验证下
验证已修复
求助,RestController 里面接口最后返回分页结果时报错 java.lang.OutOfMemoryError: try enabling LargeObject feature instead at com.alibaba.fastjson2.JSONWriterUTF16.ensureCapacity(JSONWriterUTF16.java:1998) at com.alibaba.fastjson2.JSONWriterUTF16.writeStringEscape(JSONWriterUTF16.java:424) at com.alibaba.fastjson2.JSONWriterUTF16JDK8UF.writeString(JSONWriterUTF16JDK8UF.java:56) at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:494) at com.alibaba.fastjson2.writer.ObjectWriterImplList.write(ObjectWriterImplList.java:364) at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:565) at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:565) at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:565) at com.alibaba.fastjson.JSON.toJSONString(JSON.java:1570) at com.ke.iprd.log.builder.LogBuilder.build(LogBuilder.java:123) at com.ke.iprd.log.filter.HttpRequestFilter.logResponse(HttpRequestFilter.java:300) at com.ke.iprd.log.filter.HttpRequestFilter.doFilter(HttpRequestFilter.java:160) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:94) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.lianjia.infrastructure.sentinel.web.adapter.servlet.WebMvcSentinelFilter.doFilterInternal(WebMvcSentinelFilter.java:80) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.lianjia.infrastructure.sentinel.web.adapter.servlet.WebMvcSentinelGlobalFilter.doFilterInternal(WebMvcSentinelGlobalFilter.java:54) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:114) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:104) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.lianjia.infrastructure.graceful.reload.filter.HealthCheckFilter.doFilter(HealthCheckFilter.java:65) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 要怎么解呢?
前提
项目使用了 PageHelper 进行查询分页,并提供了一个便捷转换分页模型的方法
问题
由于服务提供者使用了 PageHelper 的 Page 分页对象,并且 Page 是继承于 ArrayList 的,Page#getResult 方法返回的 this 在序列化时,实际写出去的并不是基于接口定义的类型,而是返回的实际类型
JSONB dump
其他信息