使用Jackson的注解@JsonAutoDetect来标识bean属性自动检测级别
1. ANY:任何级别的字段都可以自动识别
2. NONE:所有字段都不可以自动识别
3. NON_PRIVATE:非private修饰的字段可以自动识别
4. PROTECTED_AND_PUBLIC:被protected和public修饰的字段可以被自动识别
5. PUBLIC_ONLY:只有被public修饰的字段才可以被自动识别
6. DEFAULT:同PUBLIC_ONLY
public class NetSearchRes { protected int returnCode; protected String keyWord; public void setReturnCode(int returnCode) { this.returnCode = returnCode; } public void setKeyWord(String keyWord) { this.keyWord = keyWord; } } import org.codehaus.jackson.annotate.JsonAutoDetect; import com.ztx.bd.webservice.schemas.NetSearchRes; @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC) public class Info extends NetSearchRes { private String info; private int infoType; private String source; public String getInfo() { return info; } public void setInfo(String info) { this.info = info; } public int getInfoType() { return infoType; } public void setInfoType(int infoType) { this.infoType = infoType; } public String getSource() { return source; } public void setSource(String source) { this.source = source; } }
参考《jackson annotations注解详解 》http://blog.csdn.net/sdyy321/article/details/40298081
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。