Video: Vim li cas peb thiaj siv @JsonProperty?
2024 Tus sau: Lynn Donovan | [email protected]. Kawg hloov kho: 2023-12-15 23:47
Cov @ Json Khoom lus piav qhia yog siv txhawm rau daim ntawv qhia cov npe khoom nrog JSON yuam sij thaum serialization thiab deserialization. Koj ua tau kuj siv cov lus piav qhia no thaum lub sij hawm deserialization thaum cov cuab yeej npe ntawm JSON thiab cov npe ntawm cov khoom Java ua tsis phim.
Tsis tas li ntawd, kev siv @JsonIgnore yog dab tsi?
@ JsonIgnore yog siv kom tsis quav ntsej cov cuab yeej cuab tam siv nyob rau hauv serialization thiab deserialization. @ JsonIgnore tuaj yeem yog siv ntawm setter, getter los yog teb. Nws yog siv raws li nram no. Nyob rau hauv tag nrho cov saum toj no cov cuab yeej logical yog qeb.
Qhov thib ob, @JsonProperty yog dab tsi hauv khau raj caij nplooj ntoos hlav? Lub @JsonIgnoreProperties annotation yog siv nyob rau hauv cov chav kawm ntawv tsis quav ntsej cov teb thaum lub sij hawm serialization thiab deserialization. Cov khoom uas tau tshaj tawm hauv cov lus piav qhia no yuav tsis tau ua raws li JSON cov ntsiab lus. Cia peb xav txog ib qho piv txwv ntawm chav kawm Java uas siv @JsonIgnoreProperties annotation.
Kuj nug, siv JsonCreator yog dab tsi?
Jackson annotation @ JsonCreator yog siv qhia rau Jackson tias Java khoom muaj tus tsim (tus tsim "tus tsim") uas tuaj yeem phim cov teb ntawm JSON cov khoom rau thaj chaw ntawm Java khoom.
@JsonManagedReference thiab @JsonBackReference yog dab tsi?
@ JsonManagedReference thiab @JsonBackReference yog siv los lis cov ntaub ntawv ncig. @ JsonManagedReference yog siv rau tus menyuam siv ntawm lub hom phiaj POJO. @ JsonBackReference yog siv nyob rau hauv cov chav kawm me nyuam sib raug. Nws yog muab tso rau hauv lub back-reference khoom.