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] 保持POJO字段定义顺序输出不起作用 #1712 #2959

Closed
hks2002 opened this issue Sep 15, 2024 · 1 comment
Closed

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

hks2002 opened this issue Sep 15, 2024 · 1 comment
Assignees
Labels
bug Something isn't working fixed
Milestone

Comments

@hks2002
Copy link

hks2002 commented Sep 15, 2024

问题描述

保持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), 两者任意一个都能保持字段定义的顺序。

@hks2002 hks2002 added the bug Something isn't working label Sep 15, 2024
@hks2002 hks2002 changed the title [BUG] 保持字段排序功能不起作用 #1712 [BUG] 保持POJO字段定义顺序输出不起作用 #1712 Sep 15, 2024
@yanxutao89 yanxutao89 mentioned this issue Sep 16, 2024
3 tasks
wenshao pushed a commit that referenced this issue Sep 16, 2024
* fix consistent with declared orders when alphabetic is false, for issue #2959

* fix checkstyle
@wenshao wenshao added this to the 2.0.53 milestone Sep 16, 2024
@wenshao wenshao added the fixed label Sep 16, 2024
@wenshao
Copy link
Member

wenshao commented Sep 16, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.53
问题已修复,请用新版本

@wenshao wenshao closed this as completed Sep 16, 2024
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