使用Lombok注释生成JSON请求主体
我尝试了多种模式,但仍然没有成功,如何使用嵌套的JSON对象创建JSON数组对象,如下以下类似的类似
{
"deduction": [
{
"id": "50258779",
"amount": {
"value": 13.24,
"currency": "INR"
},
"transfer": "DEPOSIT",
"fund": "RL",
"description": "TD description",
"code": "codeNumber"
},
{
"id": "50258779",
"amount": {
"value": 13.24,
"currency": "INR"
},
"transfer": "DEPOSIT",
"fund": "RL",
"description": "TD description",
"code": "codeNumber"
}
]
}
我生成的类来构建此请求架构:
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Builder
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Transf{
private List<Deduction> deduction;
@Builder
@Getter
@Setter
public class Deduction {
private Amount amount;
private String transfer;
private String code;
private String fund;
private String description;
private Integer id;
}
@Builder
@Getter
@Setter
public class Amount {
private String currency;
private Double value;
}
}
尝试创建JSON请求boston以使用REST的速度发送,
public Transf trans()
{
return Transf.builder()
.deduction(Transf.Deduction.builder().transfer("")).build();
}
但在上面获得语法错误这,需要知道我该如何完成这项工作
I tried multiple pattern , but still no success how can I create JSON Array object with nested JSON object similar like below
{
"deduction": [
{
"id": "50258779",
"amount": {
"value": 13.24,
"currency": "INR"
},
"transfer": "DEPOSIT",
"fund": "RL",
"description": "TD description",
"code": "codeNumber"
},
{
"id": "50258779",
"amount": {
"value": 13.24,
"currency": "INR"
},
"transfer": "DEPOSIT",
"fund": "RL",
"description": "TD description",
"code": "codeNumber"
}
]
}
I had generated Class to build this request schema :
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Builder
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Transf{
private List<Deduction> deduction;
@Builder
@Getter
@Setter
public class Deduction {
private Amount amount;
private String transfer;
private String code;
private String fund;
private String description;
private Integer id;
}
@Builder
@Getter
@Setter
public class Amount {
private String currency;
private Double value;
}
}
Trying to create json request body to be send using rest assured
public Transf trans()
{
return Transf.builder()
.deduction(Transf.Deduction.builder().transfer("")).build();
}
But getting syntax error on this , need to know how can I make this work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
而不是
你需要
Instead of
you need to have
首先,您定义
私有列表&lt; dectuction&gt;扣除;
- &gt;您将提供list
。第二,要使构建器起作用,您必须调用
.build()
First, you define
private List<Deduction> deduction;
--> you will supplyList
.Second, to make builder work, you have to call
.build()