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]对List类型字段添加 @JSONField serializeUsing 无效. #1948

Closed
wangjing112 opened this issue Oct 23, 2023 · 2 comments
Closed

[BUG]对List类型字段添加 @JSONField serializeUsing 无效. #1948

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

Comments

@wangjing112
Copy link

问题描述

给list的字段添加了@JSONField(serializeUsing=FieldWriteTest.class)
FieldWriteTest 对象创建了,但是并不会回调write 方法.

环境信息

请填写以下信息:

  • 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]
import java.lang.reflect.Type;
import java.util.List;

import org.junit.Test;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.annotation.JSONField;
import com.alibaba.fastjson2.writer.ObjectWriter;
import com.google.common.collect.Lists;

public class JSONSerializeUsingTest {
	
	@Test
	public void test() {
		A a = new A();
		
		a.list = Lists.newLinkedList();
		a.list.add("test 1");
		a.list.add("test 2");
		
		String str = JSON.toJSONString(a);
		
		System.out.print(str);
	}

	public static class A{
		@JSONField(serializeUsing=FieldWriteTest.class)
		public List<String> list;
	}

    public static class FieldWriteTest implements ObjectWriter<List<String>>{

		@Override
		public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
			System.out.print("in write!");
		}
    }
}

看不到输出“in write!"

@wangjing112 wangjing112 added the bug Something isn't working label Oct 23, 2023
@yanxutao89 yanxutao89 self-assigned this Oct 27, 2023
yanxutao89 added a commit to yanxutao89/fastjson2 that referenced this issue Oct 27, 2023
@wenshao wenshao added the fixed label Oct 28, 2023
@wenshao wenshao added this to the 2.0.42 milestone Oct 28, 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

3 participants