This repository was archived by the owner on Jul 29, 2026. It is now read-only.
Description #Example
import com .alibaba .fastjson .JSONObject ;
import com .alibaba .fastjson .annotation .JSONField ;
import java .io .Serializable ;
import lombok .AllArgsConstructor ;
import lombok .Builder ;
import lombok .NoArgsConstructor ;
public class Test {
@ lombok .Data
@ NoArgsConstructor
@ AllArgsConstructor
@ Builder
public static class Req implements Serializable {
@ JSONField (name = "method" , defaultValue = "payStatus" )
private String method ;
@ JSONField (name = "merchantCode" )
private String merchantCode ;
@ JSONField (name = "data" )
private String data ;
}
public static void main (String [] args ) {
Test .Req req = Test .Req .builder ().merchantCode ("b" ).data ("c" ).build ();
String json = JSONObject .toJSONString (req );
JSONObject jsonObject = (JSONObject ) JSONObject .toJSON (req );
System .out .println (json ); //{"data":"c","merchantCode":"b","method":"payStatus"}
System .out .println (jsonObject ); //{"merchantCode":"b","data":"c"}
}
}
已经在com.alibaba.fastjson.serializer.FieldSerializer#getPropertyValue方法中增加了逻辑,看你们觉得是否要合并下这块代码
if (propertyValue == null ) {
JSONField jsonField = fieldInfo .getAnnotation ();
if (jsonField != null && !"" .equals (jsonField .defaultValue ())) {
propertyValue = jsonField .defaultValue ();
}
}
相关补丁
Reactions are currently unavailable
#Example
已经在
com.alibaba.fastjson.serializer.FieldSerializer#getPropertyValue方法中增加了逻辑,看你们觉得是否要合并下这块代码相关补丁