我需要?jiǎng)?chuàng)建一個(gè)新的注釋,用于在環(huán)境變量var == false. 我嘗試使用JsonAnnotationIntrospector,但無法獲得預(yù)期的輸出。public class Vehicle { String vehicle_name; String vehicle_model; //getters and setters @MyAnnotation public String getVehicle_model() { return vehicle_model; }}這里我需要?jiǎng)h除vehicle_model環(huán)境變量時(shí)的屬性var == false。@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.METHOD})@JsonIgnorepublic @interface MyAnnotation {}這是我自定義注解的聲明。有人可以告訴我應(yīng)該如何編寫 Introspector 部分以獲得我需要的功能嗎?提前致謝。編輯:我的嘗試 JacksonAnnotationIntrospectorpublic class MyAnnotationIntrospector extends JacksonAnnotationIntrospector {@Overridepublic boolean hasIgnoreMarker(AnnotatedMember annotatedMember) { //need this part } }的實(shí)現(xiàn)ObjectMapper是 ObjectMapper mapper = new ObjectMapper(); String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this);
添加回答
舉報(bào)
0/150
提交
取消