第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

庫(kù)類的 JSON snake case

庫(kù)類的 JSON snake case

郎朗坤 2023-06-14 13:55:06
我有一個(gè)類正在擴(kuò)展一些庫(kù)類。如何將類屬性擴(kuò)展為駝峰式大小寫。@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)class Test extends Abc {}// Library class which I can't modifyclass Abc {  private firstName; }如何將firstName設(shè)為first_name
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊

你可以使用 mixin ?;旧?,您在另一個(gè)類上定義注釋,然后將真實(shí)類與 objectMapper 中的 mixin 相關(guān)聯(lián)


public class JacksonMixin {

    @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)

    @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)

    abstract class MixinAbc{}


    // Library class which I can't modify

    class Abc {

      private String firstName;


     }


    @Test

    public void testMixin() throws JsonProcessingException {

        ObjectMapper objectMapper = new ObjectMapper();

        objectMapper.addMixIn(Abc.class, MixinAbc.class);

        Abc value = new Abc();

        value.firstName="bill";

        String writeValueAsString = objectMapper.writeValueAsString(value);

        Assert.assertEquals("{\"first_name\":\"bill\"}", writeValueAsString);


    }


}

編輯:addMixInAnnotation 已棄用,現(xiàn)在只是 addMixIn。


查看完整回答
反對(duì) 回復(fù) 2023-06-14
  • 1 回答
  • 0 關(guān)注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)