#1180·fastjson

1.2.28版本FastJsonHttpMessageConverter反序列化问题

Author: mttyddCreated May 3, 2017Updated Oct 6, 2024

1.自定义一个类继承hashmap,并在构造函数里设置一个值 2.序列化的时候用:SerializerFeature.WriteClassName 3.发送给服务端,服务端最终会执行DefaultJSONParser里365行代码,无法反序列化出正确的对象

测试代码如下:

java
public static class MyMap extends HashMap<String, Integer> {

		private static final long serialVersionUID = -3933206767511509280L;

		public MyMap() {
			this.put("uuid", 1);
		}
	}

	@Test
	public void test1() {
		MyMap map = new MyMap();
		map.put("key1", 111);
		map.put("key2", 222);

		String text = JSON.toJSONString(map, SerializerFeature.WriteClassName);
		MyMap map2 = JSON.parseObject(text, MyMap.class);
		assertTrue(111 == map2.get("key1")); // error
	}