Skip to content

Commit

Permalink
fix consistent with declared orders when alphabetic is false, for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yanxutao89 committed Sep 16, 2024
1 parent a627c5f commit ef545f5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ public ObjectWriter createObjectWriter(
}

long writerFieldFeatures = features | beanFeatures;
final boolean fieldBased = (writerFieldFeatures & JSONWriter.Feature.FieldBased.mask) != 0 && !objectClass.isInterface();
final boolean fieldBased = ((writerFieldFeatures & JSONWriter.Feature.FieldBased.mask) != 0 && !objectClass.isInterface())
|| !beanInfo.alphabetic;

if (Throwable.class.isAssignableFrom(objectClass)
|| BeanUtils.isExtendedMap(objectClass)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.alibaba.fastjson2.issues_2900;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.annotation.JSONType;
import lombok.Data;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2959 {
@Test
public void test() {
assertEquals("{\"projectNO\":null,\"orderNO\":null,\"orderType\":null,\"PN\":null,\"qty\":null,\"description\":null,\"customerCode\":null,\"customerName\":null,\"currency\":null,\"netPrice\":null,\"USD\":null,\"rate\":null,\"orderDate\":null,\"requestDate\":null,\"planedDate\":null,\"this$0\":null}",
JSON.toJSONString(new TobeDelivery(), JSONWriter.Feature.WriteNulls));
}

@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;
}
}

0 comments on commit ef545f5

Please sign in to comment.