如何放心地序列化java关键字

发布于 2025-01-10 19:44:20 字数 1019 浏览 0 评论 0原文

我正在使用放心的编程语言 JAVA 测试 API,我面临着将 JSON 有效负载序列化为 java 对象的问题。 我有一个以下 JSON 有效负载:

{
  "orderId": "Ybpv82lJ", 
  "total": "5",
  "currencyId": "Belm3pnb",
  "localCurrencyRate": 1,
  "for": "2218",
  "recipientName": "new Order",
  "numberOfPayments": 1,
  "holderFullName": "Name ",
  "holderIdNumber": "123456",
  "lastFourDigits": "4544",
  "timezone": 360
}

正如您在上面的 JSON 有效负载中看到的,我有一个 java 保留关键字 for
所以当我创建 POJO 类时,我遇到了这个问题 ,我有以下 POJO 类

@Data
public class CardReceiptRoot {
    public Integer localCurrencyRate;
    private String for;                     // this is where I'm facing the issue
    private String orderId;
    private String currencyId;
    private String total;
    private String recipientName;
    private Integer numberOfPayments;
    private String holderFullName;
    private String holderIdNumber;
    private String lastFourDigits;
    private Integer timezone;
}

我该如何处理它,如果您有任何想法请帮助我,提前感谢!

I'm testing API with rest assured programming language is JAVA, I'm facing an issue with serialising JSON payload to java object.
I have a following JSON payload:

{
  "orderId": "Ybpv82lJ", 
  "total": "5",
  "currencyId": "Belm3pnb",
  "localCurrencyRate": 1,
  "for": "2218",
  "recipientName": "new Order",
  "numberOfPayments": 1,
  "holderFullName": "Name ",
  "holderIdNumber": "123456",
  "lastFourDigits": "4544",
  "timezone": 360
}

as u can see in above JSON payload , I have a java reserved keyword for
so when I'm creating my POJO class , I'm facing the issue
, I have the following POJO class

@Data
public class CardReceiptRoot {
    public Integer localCurrencyRate;
    private String for;                     // this is where I'm facing the issue
    private String orderId;
    private String currencyId;
    private String total;
    private String recipientName;
    private Integer numberOfPayments;
    private String holderFullName;
    private String holderIdNumber;
    private String lastFourDigits;
    private Integer timezone;
}

how can I deal with it , pls help me if u have any ideas , thanks in advance !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

影子是时光的心 2025-01-17 19:44:20

此解决方案可能会帮助您:

import com.fasterxml.jackson.annotation.JsonProperty;
...
@JsonProperty("for")
private String forId;

This solution might help you:

import com.fasterxml.jackson.annotation.JsonProperty;
...
@JsonProperty("for")
private String forId;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文