
序列化
文章平均质量分 53
fastjson、Jackson、Gson
旭东怪
这个作者很懒,什么都没留下…
展开
-
Fastjson JSONException: illegal identifier : \pos 2, line 1, column 3问题解决
SO JSON在线提供在线JSON解析,可以把JSON内容或JSON文件进行格式化解析,按JSON层级展现。当JSON格式出现问题,采用中文的方式提醒JSON错误内容,以及标记JSON解析错误位置。SOJSON在线工具立志做一个完美的在线工具站,不仅仅是JSON在线工具,还有很多其他的在线工具。JSON在线 | JSON解析格式化—SO JSON在线工具。原创 2022-12-29 16:44:02 · 7355 阅读 · 0 评论 -
Jackson Cannot deserialize value of type `xxx` from String “xxx“ : Failed to deserialize xxx问题解决
问题描述:com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDateTime` from String "2022-05-18 11:35:35": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2原创 2022-05-22 09:45:28 · 3765 阅读 · 1 评论 -
Jackson 序列化和反序列化方法(单个实体、集合)
目录1 Maven依赖2 TestModel3 序列化和反序列化3.1 单个实体3.2 集合1 Maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </.原创 2022-05-21 10:39:00 · 676 阅读 · 0 评论 -
Gson 序列化和反序列化方法(单个实体、集合)
1 Maven依赖 <!-- gson 序列化工具 --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.5</version> </d原创 2022-05-20 09:05:21 · 571 阅读 · 0 评论 -
Gson Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $问题解决
问题描述:com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $问题分析:1、将一个List对象序列化之后,使用fromJson(String json, Class<T> classOfT)方法反序列化为List对象,使用的反序列化方法不对导致失败。原创 2022-05-19 09:43:52 · 3949 阅读 · 0 评论 -
Java java.lang.UnsupportedOperationException: null问题解决
问题描述:java.lang.UnsupportedOperationException: null问题分析:1、使用Gson进行序列化,但是使用fastjson进行反序列化,由于fastjson不支持Gson序列化LocalDate、LocalDateTime类型数据之后的json数据,导致报错。 List<TestModel> testModelList = new ArrayList<>(); TestModel testMode原创 2022-05-18 10:37:14 · 10485 阅读 · 0 评论 -
Java Cannot deserialize instance of `xxx` out of START_ARRAY token问题2种情况解决(Java、Jackson)
问题描述:org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot原创 2021-06-28 11:23:40 · 38393 阅读 · 0 评论 -
FastJson com.alibaba.fastjson.JSONException: parseInt error, field : id问题解决
问题描述:com.alibaba.fastjson.JSONException: parseInt error, field : id问题分析:1、使用JSON.parseArray()进行实体类类型转换时,UserEntity的id属性类型为Long,而UserDto的id属性类型为Integer,导致UserEntity转换为UserDto时,Long类型转换不了Integer类型,导致报错。 List<UserEntity> userEnti...原创 2021-10-31 20:54:20 · 20605 阅读 · 0 评论 -
FastJson 给Long类型指定序列化类无效问题解决
问题描述: /** * 全局序列化方式 * * @param converters */ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { //fastjson的全局序列化方式 configureFastJsonHttpMessageConverter(co原创 2021-10-03 21:19:26 · 1811 阅读 · 0 评论 -
Java 后端将Long类型数据序列化之后传给前端出现数据精度失真问题解决
问题描述:后端代码Long数据为201511200001725439。 @GetMapping("/getUser") public User getUser(){ User user=new User(201511200001725439L,"xudongmaster","123"); return user; }前端接收的数据就变为201511200001725440。但是PostMan不会出现这种情况,只有js才接收请求才会有这个问题原创 2021-05-13 21:11:41 · 1621 阅读 · 0 评论 -
Spring Boot实现全局序列化配置(Jackson、FastJson)
1JsonConfig序列化配置类。package com.config;import com.fasterxml.jackson.databind.DeserializationFeature;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.module.SimpleModule;import com.fasterxml.jackson.databind..原创 2021-10-01 22:40:04 · 4728 阅读 · 1 评论 -
Jackson 全局序列化配置的2种实现方式(@Bean注解创建ObjectMapper、重写configureMessageConverters方法)
1 @Bean注解创建ObjectMapper实现1.1JsonConfig全局序列化配置类。package com.config;import com.fasterxml.jackson.databind.DeserializationFeature;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.module.SimpleModule;import .原创 2021-09-30 16:18:02 · 6374 阅读 · 1 评论 -
FastJson java.lang.IllegalArgumentException: Content-Type cannot contain wildcard type ‘*‘问题解决
问题描述:java.lang.IllegalArgumentException: Content-Type cannot contain wildcard type '*'问题分析:1、FastJson 1.2版本中需要用户自己配置MediaType,否则会报错。解决办法:调用FastJsonHttpMessageConverter.setSupportedMediaTypes()添加需要配置MediaType即可。 /** * fastjson的全局序列化方式原创 2021-10-02 22:41:35 · 1581 阅读 · 0 评论