我需要创建一个新的注释,用于在环境变量var == false. 我尝试使用JsonAnnotationIntrospector,但无法获得预期的输出。public class Vehicle { String vehicle_name; String vehicle_model; //getters and setters @MyAnnotation public String getVehicle_model() { return vehicle_model; }}这里我需要删除vehicle_model环境变量时的属性var == false。@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.METHOD})@JsonIgnorepublic @interface MyAnnotation {}这是我自定义注解的声明。有人可以告诉我应该如何编写 Introspector 部分以获得我需要的功能吗?提前致谢。编辑:我的尝试 JacksonAnnotationIntrospectorpublic class MyAnnotationIntrospector extends JacksonAnnotationIntrospector {@Overridepublic boolean hasIgnoreMarker(AnnotatedMember annotatedMember) { //need this part } }的实现ObjectMapper是 ObjectMapper mapper = new ObjectMapper(); String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this);
添加回答
举报
0/150
提交
取消