java - Is @JsonProperty annotation required on accessor methods? -


i've inherited following:

import com.fasterxml.jackson.annotation.jsonproperty; public class myclass {   @jsonproperty("id")   private string id;    @jsonproperty("id")   public string getid(){     ...code...   }    @jsonproperty("id")   public string setid(string id) {     ...code...   } } 

are repeated jsonproperty annotations required on getter , setter, or jackson handle serialization/deserialization automatically if annotated private member?

in example, , default objectmapper settings, no annotations should needed, when using jackson 1.8 or newer.

jackson can auto-detect properties public getters (like "public int getvalue()"), setters ("public void setvalue(int v);" , fields ("public int value;"). in addition, long 1 public setter, getter or field found, matching (otherwise) non-visible setter/field included.

note, however, old jackson versions (1.7 , earlier) did not second part, , both setter , getter needed public.


Comments