Skip to content

Commit

Permalink
Fix 2959 (#2960)
Browse files Browse the repository at this point in the history
* fix consistent with declared orders when alphabetic is false, for issue #2959

* fix checkstyle
  • Loading branch information
yanxutao89 authored Sep 16, 2024
1 parent a627c5f commit 4686c2c
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 4686c2c

Please sign in to comment.