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

不支持javaBean为Builder模式的链式编程 #2346

Closed
luoylove opened this issue Mar 29, 2019 · 1 comment
Closed

不支持javaBean为Builder模式的链式编程 #2346

luoylove opened this issue Mar 29, 2019 · 1 comment
Milestone

Comments

@luoylove
Copy link

luoylove commented Mar 29, 2019

当json串反序列化成JavaBean时,该javaBean是Builder模式的链式编程结果,反序列化失败,未找到默认构造函数
javaBean如下:

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Builder
@Getter
@Setter
public class TestEntity {
	private String name;
	
	private int age;
}

序列化代码如下:

import com.alibaba.fastjson.JSON;

public class Test {
	public static void main(String[] args) {
		String jsonStr = "{\"age\":1,\"name\":\"aa\"}";
		
		TestEntity testEntity = JSON.parseObject(jsonStr, TestEntity.class);
	}
}

错误如下:

Exception in thread "main" com.alibaba.fastjson.JSONException: default constructor not found. class com.dzcx.test.TestEntity
	at com.alibaba.fastjson.util.JavaBeanInfo.build(JavaBeanInfo.java:519)
	at com.alibaba.fastjson.parser.ParserConfig.createJavaBeanDeserializer(ParserConfig.java:728)
	at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:645)
	at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:394)
	at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:669)
	at com.alibaba.fastjson.JSON.parseObject(JSON.java:369)
	at com.alibaba.fastjson.JSON.parseObject(JSON.java:273)
	at com.alibaba.fastjson.JSON.parseObject(JSON.java:546)
	at com.dzcx.test.Test.main(Test.java:9)

版本:1.2.55

@wenshao wenshao added this to the 1.2.58 milestone Apr 11, 2019
@thiner
Copy link

thiner commented Jun 17, 2019

你需要为你的类加上@NoArgsConstructor,但是这个注解跟@builder 冲突,所以你还要再加上@AllArgsConstructor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants