Skip to content

[BUG] 保持POJO字段定义顺序输出不起作用 #1712 #2959

@hks2002

Description

@hks2002

问题描述

保持POJO中定义的字段顺序不生效

重现步骤

  1. 仅仅设置alphabetic = false不能保持Bean的字段顺序。
  2. 同时设置JJSONWriter.Feature.FieldBased才起作用。
import java.math.BigDecimal;
import java.util.Date;

import com.alibaba.fastjson2.annotation.JSONType;

import lombok.Data;

@Data
@JSONType(alphabetic = false)
public class TobeDelivery {

    private String ProjectNO;
    private String OrderNO;
    private String OrderType;
    private String PN;
    private Integer Qty;
    private String Description;
    private String CustomerCode;
    private String CustomerName;
    private String Currency;
    private BigDecimal NetPrice;
    private BigDecimal USD;
    private Float Rate;
    private Date OrderDate;
    private Date RequestDate;
    private Date PlanedDate;
}
JSON.config(JSONWriter.Feature.FieldBased);

期待的正确结果

输出的json字段和pojo定义的一样。
image

这个描述,容易理解为设置了,就能按定义字段的顺序进行输出。
image

建议

设置@jsontype(alphabetic = false) 或者JSON.config(JSONWriter.Feature.FieldBased), 两者任意一个都能保持字段定义的顺序。

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixed

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions