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

[BUG][v2.0.45/2.0.44]反序列化字符串中最后一个包含转义字符(如:\r、\n、\r\n等)不支持Double类型 #2164

Closed
805728578 opened this issue Jan 9, 2024 · 1 comment
Labels
bug Something isn't working fixed
Milestone

Comments

@805728578
Copy link

805728578 commented Jan 9, 2024

问题描述

简要描述您碰到的问题。

环境信息

请填写以下信息:

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.45/2.0.44]

重现步骤

如何操作可以重现该问题:

  1. 使用 xxx.xxx 方法
  2. 输入 ... 数据
  3. 出现 ... 错误

测试场景1:

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

public class JSONTest {
	@Setter
	@Getter
	@NoArgsConstructor
	@AllArgsConstructor
	@ToString
	public static class TestVO{
		private String Ref;
		private Double Width;
		private Double High;
	}
	/**
	 * Fastjson默认读特性
	 */
	public static final JSONReader.Feature[] FASTJSON_DEFAULT_READER_FEATURES = {JSONReader.Feature.SupportSmartMatch, JSONReader.Feature.SupportArrayToBean, JSONReader.Feature.UseNativeObject, JSONReader.Feature.SupportClassForName,JSONReader.Feature.IgnoreSetNullValue,JSONReader.Feature.AllowUnQuotedFieldNames,JSONReader.Feature.IgnoreCheckClose,JSONReader.Feature.IgnoreAutoTypeNotMatch };
	
	public static void main(String[] args) {
		String json = "{\r\n"
				+ "	\"Ref\": \"\",\r\n"
				+ "	\"Width\": \"\",\r\n"
				+ "	\"High\": \"\"\r\n"
				+ "}";
//		String json = "{\"Ref\": \"\",\"Width\": \"\",\"High\": \"\"}";
		TestVO jsonRootBean = JSON.parseObject(json, TestVO.class, FASTJSON_DEFAULT_READER_FEATURES);
	     System.out.println(jsonRootBean);
	}
}

测试场景2:

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

public class JSONTest {
	@Setter
	@Getter
	@NoArgsConstructor
	@AllArgsConstructor
	@ToString
	public static class TestVO{
		private String Ref;
		private Double Width;
		private Double High;
	}
	/**
	 * Fastjson默认读特性
	 */
	public static final JSONReader.Feature[] FASTJSON_DEFAULT_READER_FEATURES = {JSONReader.Feature.SupportSmartMatch, JSONReader.Feature.SupportArrayToBean, JSONReader.Feature.UseNativeObject, JSONReader.Feature.SupportClassForName,JSONReader.Feature.IgnoreSetNullValue,JSONReader.Feature.AllowUnQuotedFieldNames,JSONReader.Feature.IgnoreCheckClose,JSONReader.Feature.IgnoreAutoTypeNotMatch };
	
	public static void main(String[] args) {
		String json = "{\r\n"
				+ "	\"Ref\": \"\",\r\n"
				+ "	\"Width\": \"\",\r\n"
				+ "	\"High\": \"\""
				+ "}";
//		String json = "{\"Ref\": \"\",\"Width\": \"\",\"High\": \"\"}";
		TestVO jsonRootBean = JSON.parseObject(json, TestVO.class, FASTJSON_DEFAULT_READER_FEATURES);
	     System.out.println(jsonRootBean);
	}
}

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。
期望测试场景1测试场景2结果一致

目前测试结果如下:
测试场景1:报错
测试场景2:正常

相关日志输出

请复制并粘贴任何相关的日志输出。
image

关键问题出现在

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@805728578 805728578 added the bug Something isn't working label Jan 9, 2024
@805728578 805728578 changed the title [BUG][v2.0.45]反序列化字符串中最后一个包含转义字符(如:\r、\n、\r\n等)不支持Double类型 [BUG][v2.0.45/2.0.44]反序列化字符串中最后一个包含转义字符(如:\r、\n、\r\n等)不支持Double类型 Jan 9, 2024
@wenshao wenshao added this to the 2.0.46 milestone Jan 16, 2024
@wenshao wenshao added the fixed label Jan 16, 2024
@wenshao
Copy link
Member

wenshao commented Jan 29, 2024

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

@wenshao wenshao closed this as completed Jan 29, 2024
wenshao pushed a commit that referenced this issue Mar 8, 2024
…2296 (#2299)

* nextIfComma supports ignoring all white space chars, for issue #2164
* fix JSONReader#readObject unprocessed reference detection,for issue #2296
wenshao pushed a commit that referenced this issue Oct 12, 2024
…ype fields, for issue #3076 (#3077)

* nextIfComma supports ignoring all white space chars, for issue #2164

* Fix ClassCastException caused by using ValueFilter in Boolean/Short type fields, for issue #3076
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants