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]@JSONField(serializeFeatures= {JSONWriter.Feature.WriteClassName}) 无效 #1947

Closed
wangjing112 opened this issue Oct 23, 2023 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@wangjing112
Copy link

wangjing112 commented Oct 23, 2023

问题描述

在字段三标注 @JSONField(serializeFeatures= {JSONWriter.Feature.WriteClassName})
无效

环境信息

请填写以下信息:

  • 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.41]

code:

import org.junit.Test;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.annotation.JSONField;

public class JSONTypeWrite {
	
	@Test
	public void test() {
		A a = new A();
		a.id = 1;
		a.name = "a";
		
		B b = new B();
		b.id = 2;
		
		
		C c = new C();
		c.list = new ID[] {a,b};
		
		String str = JSON.toJSONString(c);
		System.out.printf(str);
	}
	
	public static class C{
		@JSONField(serializeFeatures= {JSONWriter.Feature.WriteClassName})
		public ID[] list;
	}

	public static class A implements ID{
		public int id;
		public String name;
		@Override
		public int getId() {
			return id;
		}
	}
	
	public static class B implements ID{
		public int id;
		@Override
		public int getId() {
			return id;
		}
	}
	
	public static interface ID{
		int getId();
	}
}
@wangjing112 wangjing112 added the bug Something isn't working label Oct 23, 2023
@wenshao wenshao added this to the 2.0.42 milestone Oct 29, 2023
@wenshao wenshao added the fixed label Oct 29, 2023
@wenshao
Copy link
Member

wenshao commented Oct 29, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.42-SNAPSHOT/
问题已修复,请帮忙用2.0.42-SNAPSHOT版本验证,正式版本预计在下个周末(11月5日)发布。

@wenshao
Copy link
Member

wenshao commented Nov 5, 2023

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

@wenshao wenshao closed this as completed Nov 5, 2023
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