fastjson 序列化时报错:write javaBean error

6ovsh4lw  于 2021-11-27  发布在  Java
关注(0)|答案(2)|浏览(6225)

序列化时报错,错误信息如下,但加入SerializerFeature.IgnoreNonFieldGetter后没有错误,请问是什么原因导致。非常感谢:
Caused by: com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.40, class org.apache.catalina.core.StandardContext, fieldName : context, write javaBean error, fastjson version 1.2.40, class org.apache.catalina.session.StandardManager, fieldName : manager, write javaBean error, fastjson version 1.2.40, class org.apache.catalina.core.StandardEngine, fieldName : engine, Can''t generate an absolute name for this namespace
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:413)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:113)
at com.alibaba.fastjson.serializer.FieldSerializer.writeValue(FieldSerializer.java:284)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:359)
... 63 common frames omitted
Caused by: com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.40, class org.apache.catalina.session.StandardManager, fieldName : manager, write javaBean error, fastjson version 1.2.40, class org.apache.catalina.core.StandardEngine, fieldName : engine, Can''t generate an absolute name for this namespace
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:413)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:113)
at com.alibaba.fastjson.serializer.FieldSerializer.writeValue(FieldSerializer.java:284)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:359)
... 66 common frames omitted
Caused by: com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.40, class org.apache.catalina.core.StandardEngine, fieldName : engine, Can''t generate an absolute name for this namespace
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:413)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:113)
at com.alibaba.fastjson.serializer.FieldSerializer.writeValue(FieldSerializer.java:284)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:359)
... 69 common frames omitted

eoigrqb6

eoigrqb61#

我也遇到这个问题了是因为我序列化的实体中不止含有自定义的内容,还有其他的一些注解信息也被序列化了
实体:
@component
@ConfigurationProperties(prefix = "user")
@configuration
public class User implements Serializable {
private String name;
private int age;
......................................
加了SerializerFeature.IgnoreNonFieldGetter后序列化得到的json串:
{
"$$beanFactory": {
"allowBeanDefinitionOverriding": false,
"allowEagerClassLoading": true,
"autowireCandidateResolver": {},
"beanDefinitionNames": ["org.springframework.context.annotation.internalConfigurationAnnotationProcessor", "org.springframework.context.annotation.internalAutowiredAnnotationProcessor", "org.springframework.context.annotation.internalCommonAnnotationProcessor", "org.springframework.context.event.internalEventListenerProcessor", "org.springframework.context.event.internalEventListenerFactory", "springboot02Application", "org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory", "helloWorld", "user", "org.springframework.boot.autoconfigure.AutoConfigurationPackages", "org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration", "propertySourcesPlaceholderConfigurer", "org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration", "websocketServletWebServerCustomizer", "org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration", "org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat", "tomcatServletWebServerFactory", "org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration", "servletWebServerFactoryCustomizer", "tomcatServletWebServerFactoryCustomizer", "org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor", "org.springframework.boot.context.internalConfigurationPropertiesBinderFactory", "org.springframework.boot.context.internalConfigurationPropertiesBinder", "org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator", "org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata", "server-org.springframework.boot.autoconfigure.web.ServerProperties", "webServerFactoryCustomizerBeanPostProcessor", "errorPageRegistrarBeanPostProcessor", "org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration", "dispatcherServlet", "spring.http-org.springframework.boot.autoconfigure.http.HttpProperties", "spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties", "org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration", "dispatcherServletRegistration", "org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration", "org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration", "taskExecutorBuilder", "applicationTaskExecutor", "spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties", "org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration", "defaultValidator", "methodValidationPostProcessor", "org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration", "error", "beanNameViewResolver", "org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration", "conventionErrorViewResolver", "org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration", "errorAttributes", "basicErrorController", "errorPageCustomizer", "preserveErrorControllerTargetClassPostProcessor", "spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties", "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration", "requestMappingHandlerAdapter", "requestMappingHandlerMapping", "welcomePageHandlerMapping", "mvcConversionService", "mvcValidator", "mvcContentNegotiationManager", "mvcPathMatcher", "mvcUrlPathHelper", "viewControllerHandlerMapping", "beanNameHandlerMapping", "routerFunctionMapping", "resourceHandlerMapping", "mvcResourceUrlProvider", "defaultServletHandlerMapping", "handlerFunctionAdapter", "mvcUriComponentsContributor", "httpRequestHandlerAdapter", "simpleControllerHandlerAdapter", "handlerExceptionResolver", "mvcViewResolver", "mvcHandlerMappingIntrospector", "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter", "defaultViewResolver", "viewResolver", "requestContextFilter", "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration", "formContentFilter", "org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration", "springApplicationAdminRegistrar", "org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$ClassProxyingConfiguration", "org.springframework.boot.autoconfigure.aop.AopAutoConfiguration", "org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration", "standardJacksonObjectMapperBuilderCustomizer", "spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration", "jacksonObjectMapperBuilder", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$ParameterNamesModuleConfiguration", "parameterNamesModule", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration", "jacksonObjectMapper", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration", "jsonComponentModule", "org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration", "stringHttpMessageConverter", "org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration", "mappingJackson2HttpMessageConverter", "org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration", "org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration", "messageConverters", "org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration", "spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties", "org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration", "spring.security.oauth2.resourceserver-org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties", "org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration", "taskSchedulerBuilder", "spring.task.scheduling-org.springframework.boot.autoconfigure.task.TaskSchedulingProperties", "org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration", "restTemplateBuilder", "org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration", "tomcatWebServerFactoryCustomizer", "org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration", "org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration", "characterEncodingFilter", "localeCharsetMappingsCustomizer", "org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration", "multipartConfigElement", "multipartResolver", "spring.servlet.multipart-org.springframework.boot.autoconfigure.web.servlet.MultipartProperties", "org.springframework.aop.config.internalAutoProxyCreator"],
"beanExpressionResolver": {},
"beanPostProcessors": [{}, {}, {}, {}, {}, {
"exposeProxy": false,
"frozen": false,
"opaque": false,
"optimize": false,
"order": 2147483647,
"proxyTargetClass": true
}, {}, {}, {
"order": 2147483644
}, {
"order": 2147483645
}, {}],
"cacheBeanMetadata": true,
"configurationFrozen": true,
"conversionService": {},
"customEditors": {},
"dependencyComparator": {},
"propertyEditorRegistrars": [{}],
"serializationId": "application",
"typeConverter": {
"conversionService": {
"$ref": "$.$$beanFactory.conversionService"
}
}
},
"age": 21,
"name": "ZHAOLEI"
}

oxosxuxt

oxosxuxt2#

俺也一样:
2021-08-23T02:40:43.888500062Z org.springframework.security.authentication.InternalAuthenticationServiceException: write javaBean error, fastjson version 1.2.75, class org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper, method : getAsyncContext 2021-08-23T02:40:43.888511552Z at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:123) 2021-08-23T02:40:43.888525096Z at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:144) 2021-08-23T02:40:43.888529865Z at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:175) 2021-08-23T02:40:43.888533971Z at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:195) 2021-08-23T02:40:43.888538174Z at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$AuthenticationManagerDelegator.authenticate(WebSecurityConfigurerAdapter.java:512) 2021-08-23T02:40:43.888542380Z at org.springblade.auth.support.QywxTokenGranter.getOAuth2Authentication(QywxTokenGranter.java:43) 2021-08-23T02:40:43.888546329Z at org.springframework.security.oauth2.provider.token.AbstractTokenGranter.getAccessToken(AbstractTokenGranter.java:72) 2021-08-23T02:40:43.888550283Z at org.springframework.security.oauth2.provider.token.AbstractTokenGranter.grant(AbstractTokenGranter.java:67) 2021-08-23T02:40:43.888554312Z at org.springframework.security.oauth2.provider.CompositeTokenGranter.grant(CompositeTokenGranter.java:38) 2021-08-23T02:40:43.888558396Z at org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.postAccessToken(TokenEndpoint.java:132) 2021-08-23T02:40:43.888562261Z at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2021-08-23T02:40:43.888565881Z at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2021-08-23T02:40:43.888570931Z at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2021-08-23T02:40:43.888574925Z at java.lang.reflect.Method.invoke(Unknown Source) 2021-08-23T02:40:43.888578880Z at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) 2021-08-23T02:40:43.888583018Z at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) 2021-08-23T02:40:43.888587159Z at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) 2021-08-23T02:40:43.888591059Z at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) 2021-08-23T02:40:43.888600171Z at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) 2021-08-23T02:40:43.888604344Z at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 2021-08-23T02:40:43.888608397Z at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) 2021-08-23T02:40:43.888612151Z at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) 2021-08-23T02:40:43.888615808Z at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) 2021-08-23T02:40:43.888623707Z at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) 2021-08-23T02:40:43.888628073Z at javax.servlet.http.HttpServlet.service(HttpServlet.java:517) 2021-08-23T02:40:43.888632065Z at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) 2021-08-23T02:40:43.888636213Z at javax.servlet.http.HttpServlet.service(HttpServlet.java:584) 2021-08-23T02:40:43.888640308Z at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74) 2021-08-23T02:40:43.888644454Z at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129) 2021-08-23T02:40:43.888648445Z at org.springblade.core.log.filter.LogTraceFilter.doFilter(LogTraceFilter.java:39) 2021-08-23T02:40:43.888652184Z at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) 2021-08-23T02:40:43.888655697Z at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) 2021-08-23T02:40:43.888659746Z at org.springblade.auth.filter.BeforeOauthTokenFilter.doFilter(BeforeOauthTokenFilter.java:82) 2021-08-23T02:40:43.888663846Z at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)

相关问题