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

修复下划线字段hash值,取值错误bug #3246

Closed
wants to merge 1 commit into from

Conversation

ChangRuihe
Copy link

@ChangRuihe ChangRuihe commented Jun 8, 2020

多个下划线 属性字段,去掉"","-" 后,数值一致,然后取hash值一致,没有处理hash冲突。
把 "
","-" 加入hash运算,排除hash冲突;

复现代码示例:

        String jsonStr = "{\"d_id\":\"bphyean01\",\"isOpenMergeCode\":0,\"offlineOrder\":false,\"offlineOrderType\":-1,\"og\":0,\"pushIdFromRemote\":false,\"qrisAmountPrice\":22000,\"s_req\":0,\"s_t\":1,\"skr_id\":0,\"type\":1,\"c_id\":471,\"o_$\":5500.0,\"am\":4,\"$_tp\":\"bp\",\"o_t\":1,\"a_m\":3}";
        Order parseOrder = JSON.parseObject(jsonStr,Order.class);
        System.out.println("parseOrder:"+parseOrder.getAmount()+"\t"+parseOrder.getAddMoney()+"\t"+JSON.toJSONString(parseOrder));


@Data
public class Order {
    @JSONField(name = "d_id", ordinal = 0)
    private String deviceId;
    @JSONField(name = "c_id", ordinal = 1)
    private Integer commodityId;
    @JSONField(name = "o_$", ordinal = 2)
    private Double orderPrice;
    @JSONField(name = "am", ordinal = 3)
    private Integer amount;
    @JSONField(name = "$_tp", ordinal = 4)
    private String payType;
    @JSONField(name = "wx_p_id", ordinal = 5)
    private Long productId;
    @JSONField(name = "ext_p_id", ordinal = 6)
    private Long extraProductId;
    @JSONField(name = "u_id", ordinal = 7)
    private String userId;
    @JSONField(name = "p_id", ordinal = 8)
    private Long parentId;
    @JSONField(name = "o_t", ordinal = 9)
    private Integer orderType;
    @JSONField(name = "ts", ordinal = 10)
    private Integer tradeStatus;
    @JSONField(name = "pn", ordinal = 11)
    private String phoneNum;
    @JSONField(name = "conf_id", ordinal = 12)
    private Long configId;
    @JSONField(name = "sku_id", ordinal = 13)
    private Long skuCommodityId;
    @JSONField(name = "c_ids", ordinal = 14)
    private String commodityIds;
    @JSONField(name = "a_m", ordinal = 15)
    private String addMoney;
    @JSONField(name = "skr_id", ordinal = 15)
    private Long secKillRecordId;
    @JSONField(name = "c_n", ordinal = 16)
    private String clientOrderNum;
    @JSONField(name = "s_t", ordinal = 16)
    private Integer sceneType;
    @JSONField(name = "t_t", ordinal = 16)
    private Integer tradingType;

}

多个下划线 属性字段,去掉"_","-" 后,数值一致,然后取hash值一致,没有处理hash冲突。
把 "_","-" 加入hash运算,排除hash冲突;

复现代码示例:

        String jsonStr = "{\"d_id\":\"bphyean01\",\"isOpenMergeCode\":0,\"offlineOrder\":false,\"offlineOrderType\":-1,\"og\":0,\"pushIdFromRemote\":false,\"qrisAmountPrice\":22000,\"s_req\":0,\"s_t\":1,\"skr_id\":0,\"type\":1,\"c_id\":471,\"o_$\":5500.0,\"am\":4,\"$_tp\":\"bp\",\"o_t\":1,\"a_m\":3}";
        Order parseOrder = JSON.parseObject(jsonStr,Order.class);
        System.out.println("parseOrder:"+parseOrder.getAmount()+"\t"+parseOrder.getAddMoney()+"\t"+JSON.toJSONString(parseOrder));


@DaTa
public class Order {
    @JSONField(name = "d_id", ordinal = 0)
    private String deviceId;
    @JSONField(name = "c_id", ordinal = 1)
    private Integer commodityId;
    @JSONField(name = "o_$", ordinal = 2)
    private Double orderPrice;
    @JSONField(name = "am", ordinal = 3)
    private Integer amount;
    @JSONField(name = "$_tp", ordinal = 4)
    private String payType;
    @JSONField(name = "wx_p_id", ordinal = 5)
    private Long productId;
    @JSONField(name = "ext_p_id", ordinal = 6)
    private Long extraProductId;
    @JSONField(name = "u_id", ordinal = 7)
    private String userId;
    @JSONField(name = "p_id", ordinal = 8)
    private Long parentId;
    @JSONField(name = "o_t", ordinal = 9)
    private Integer orderType;
    @JSONField(name = "ts", ordinal = 10)
    private Integer tradeStatus;
    @JSONField(name = "pn", ordinal = 11)
    private String phoneNum;
    @JSONField(name = "conf_id", ordinal = 12)
    private Long configId;
    @JSONField(name = "sku_id", ordinal = 13)
    private Long skuCommodityId;
    @JSONField(name = "c_ids", ordinal = 14)
    private String commodityIds;
    @JSONField(name = "a_m", ordinal = 15)
    private String addMoney;
    @JSONField(name = "skr_id", ordinal = 15)
    private Long secKillRecordId;
    @JSONField(name = "c_n", ordinal = 16)
    private String clientOrderNum;
    @JSONField(name = "s_t", ordinal = 16)
    private Integer sceneType;
    @JSONField(name = "t_t", ordinal = 16)
    private Integer tradingType;

}
@CLAassistant
Copy link

CLAassistant commented Jun 8, 2020

CLA assistant check
All committers have signed the CLA.

wenshao added a commit that referenced this pull request Jun 9, 2020
@wenshao wenshao closed this Jun 9, 2020
@wenshao wenshao added this to the 1.2.71 milestone Jun 9, 2020
@wenshao
Copy link
Member

wenshao commented Jun 14, 2020

https://github.com/alibaba/fastjson/wiki/enum_custom_serialization
问题修复,请用新版本

@colin-lee
Copy link

colin-lee commented Jun 29, 2020

image
引起次生灾害

@wenshao @ChangRuihe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants