Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

JSONField 注解的 unwrap 特性有 bug #1474

Closed
xunux opened this issue Sep 13, 2017 · 2 comments
Closed

JSONField 注解的 unwrap 特性有 bug #1474

xunux opened this issue Sep 13, 2017 · 2 comments
Labels
Milestone

Comments

@xunux
Copy link

xunux commented Sep 13, 2017

当 JSONField 注解的参数 unwrapped 设为 true 时,若 该对象的字段值全为 null,序列化之后
会多一个逗号, fastjson版本为最新版 1.2.38

java 代码

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

public class FastjsonBugTest {
	public static void main(String[] args) {
		Map<String,Object> extraData = new HashMap<String,Object>();
		extraData.put("ext_1", null);
		extraData.put("ext_2", null);
		
		People p = new People();
		p.setId("001");
		p.setName("顾客");
		p.setExtraData(extraData);
		
		System.out.println(JSON.toJSONString(p));
	}
	
	static class People{
		private String name;
		private String id;
		@JSONField(unwrapped=true)
		private Object extraData;

		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getId() {
			return id;
		}
		public void setId(String id) {
			this.id = id;
		}
		public Object getExtraData() {
			return extraData;
		}
		public void setExtraData(Object extraData) {
			this.extraData = extraData;
		}
	}
}

预期结果:

{"id":"001","name":"顾客"}

实际结果:

{,"id":"001","name":"顾客"}
@wenshao wenshao added the bug label Sep 14, 2017
@wenshao wenshao added this to the 1.2.39 milestone Sep 14, 2017
@wenshao wenshao modified the milestones: 1.2.39, 1.2.40 Oct 1, 2017
wenshao added a commit that referenced this issue Oct 1, 2017
@wenshao
Copy link
Member

wenshao commented Oct 1, 2017

问题已经修复,将会在1.2.40版本中带上

@wenshao
Copy link
Member

wenshao commented Nov 4, 2017

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

@wenshao wenshao closed this as completed Nov 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants