Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字段类型跟实体类定义的类型不一样时解析报错 #1790

Closed
DevinYDQ opened this issue Aug 25, 2023 · 1 comment
Closed

字段类型跟实体类定义的类型不一样时解析报错 #1790

DevinYDQ opened this issue Aug 25, 2023 · 1 comment
Labels
fixed question Further information is requested
Milestone

Comments

@DevinYDQ
Copy link

DevinYDQ commented Aug 25, 2023

@Data
public class A {
        private String op;
	private JSONObject test;

	public static void main(String[] args) {
		String json = "{\"op\":\"yyy\",\"test\":\"{\\\"erw\\\":{\\\"qqq\\\":12313}}\"}";
		A a = JSON.parseObject(json, A.class);
		System.out.println(a);
	}
}

json里的test字段是带转义字符的字符串,解析时报错
Exception in thread "main" com.alibaba.fastjson2.JSONException: illegal input, offset 36, char }
at com.alibaba.fastjson2.JSONReader.read(JSONReader.java:2043)
at com.alibaba.fastjson2.reader.ObjectReaderImplMap.readObject(ObjectReaderImplMap.java:434)
at com.alibaba.fastjson2.reader.ORG_1_1_A.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:726)
at com.yumchina.uf.ms.store.service.impl.A.main(A.java:19)

问题1: 这种类型不匹配的情况该怎么解决?

问题2: 如果出现类型不匹配的字段,能否忽略该字段的解析,继续解析其他正常的字段?

@DevinYDQ DevinYDQ added the question Further information is requested label Aug 25, 2023
@wenshao wenshao added this to the 2.0.41 milestone Sep 3, 2023
@wenshao wenshao added the fixed label Oct 5, 2023
@wenshao
Copy link
Member

wenshao commented Oct 6, 2023

https://github.com/alibaba/fastjson2/releases/tag/2.0.41
问题已修复,请用新版本

@wenshao wenshao closed this as completed Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants