com.fasterxml.jackson.databind.ObjectMapper.setAnnotationIntrospector()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中com.fasterxml.jackson.databind.ObjectMapper.setAnnotationIntrospector()方法的一些代码示例,展示了ObjectMapper.setAnnotationIntrospector()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectMapper.setAnnotationIntrospector()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.ObjectMapper
类名称:ObjectMapper
方法名:setAnnotationIntrospector

ObjectMapper.setAnnotationIntrospector介绍

[英]Method for setting AnnotationIntrospector used by this mapper instance for both serialization and deserialization. Note that doing this will replace the current introspector, which may lead to unavailability of core Jackson annotations. If you want to combine handling of multiple introspectors, have a look at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.
[中]方法,该方法用于设置此映射器实例用于序列化和反序列化的AnnotationIntroSector。请注意,这样做将替换当前的内省器,这可能导致核心Jackson注释不可用。如果您想结合处理多个内省,请查看com。fasterxml。杰克逊。数据绑定。内省。注释Introjector对。

代码示例

代码示例来源:origin: jersey/jersey

private static ObjectMapper createCombinedObjectMapper() {
  return new ObjectMapper()
      .configure(SerializationFeature.WRAP_ROOT_VALUE, true)
      .configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true)
      .setAnnotationIntrospector(createJaxbJacksonAnnotationIntrospector());
}

代码示例来源:origin: apache/nifi

public ObjectMapperResolver() throws Exception {
  mapper = new ObjectMapper();
  mapper.setDefaultPropertyInclusion(Value.construct(Include.NON_NULL, Include.ALWAYS));
  mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory()));
}

代码示例来源:origin: apache/nifi

private static JacksonJaxbJsonProvider jacksonJaxbJsonProvider() {
    JacksonJaxbJsonProvider jacksonJaxbJsonProvider = new JacksonJaxbJsonProvider();

    ObjectMapper mapper = new ObjectMapper();
    mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL));
    mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory()));
    // Ignore unknown properties so that deployed client remain compatible with future versions of NiFi that add new fields
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    jacksonJaxbJsonProvider.setMapper(mapper);
    return jacksonJaxbJsonProvider;
  }
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

public static ObjectMapper getMapper() {
    ObjectMapper mapper = new ObjectMapper();
    AnnotationIntrospector aipair = new AnnotationIntrospectorPair (
      new JaxbAnnotationIntrospector(),
      new JacksonAnnotationIntrospector()
    );
    mapper.setAnnotationIntrospector(aipair);
    //REMOVE: mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, true);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return mapper;

  }
}

代码示例来源:origin: Netflix/eureka

private void bindAmazonInfoFilter(ObjectMapper mapper) {
  SimpleFilterProvider filters = new SimpleFilterProvider();
  final String filterName = "exclude-amazon-info-entries";
  mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
    @Override
    public Object findFilterId(Annotated a) {
      if (Map.class.isAssignableFrom(a.getRawType())) {
        return filterName;
      }
      return super.findFilterId(a);
    }
  });
  filters.addFilter(filterName, new SimpleBeanPropertyFilter() {
    @Override
    protected boolean include(BeanPropertyWriter writer) {
      return true;
    }
    @Override
    protected boolean include(PropertyWriter writer) {
      return MINI_AMAZON_INFO_INCLUDE_KEYS.contains(writer.getName());
    }
  });
  mapper.setFilters(filters);
}

代码示例来源:origin: spring-projects/spring-framework

objectMapper.setAnnotationIntrospector(this.annotationIntrospector);

代码示例来源:origin: allure-framework/allure2

public Allure1Plugin() {
  final SimpleModule module = new XmlParserModule()
      .addDeserializer(ru.yandex.qatools.allure.model.Status.class, new StatusDeserializer());
  xmlMapper = new XmlMapper()
      .configure(USE_WRAPPER_NAME_AS_PROPERTY_NAME, true)
      .setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()))
      .registerModule(module);
}

代码示例来源:origin: apache/nifi

public OkHttpReplicationClient(final NiFiProperties properties) {
  jsonCodec.setDefaultPropertyInclusion(Value.construct(Include.NON_NULL, Include.ALWAYS));
  jsonCodec.setAnnotationIntrospector(new JaxbAnnotationIntrospector(jsonCodec.getTypeFactory()));
  jsonSerializer = new JsonEntitySerializer(jsonCodec);
  xmlSerializer = new XmlEntitySerializer();
  okHttpClient = createOkHttpClient(properties);
}

代码示例来源:origin: jersey/jersey

@Override
protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations,
                        final Class<?> defaultView) {
  final AnnotationIntrospector customIntrospector = mapper.getSerializationConfig().getAnnotationIntrospector();
  // Set the custom (user) introspector to be the primary one.
  final ObjectMapper filteringMapper = mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(customIntrospector,
      new JacksonAnnotationIntrospector() {
        @Override
        public Object findFilterId(final Annotated a) {
          final Object filterId = super.findFilterId(a);
          if (filterId != null) {
            return filterId;
          }
          if (a instanceof AnnotatedMethod) {
            final Method method = ((AnnotatedMethod) a).getAnnotated();
            // Interested only in getters - trying to obtain "field" name from them.
            if (ReflectionHelper.isGetter(method)) {
              return ReflectionHelper.getPropertyName(method);
            }
          }
          if (a instanceof AnnotatedField || a instanceof AnnotatedClass) {
            return a.getName();
          }
          return null;
        }
      }));
  return super._configForWriting(filteringMapper, annotations, defaultView);
}

代码示例来源:origin: org.springframework/spring-web

objectMapper.setAnnotationIntrospector(this.annotationIntrospector);

代码示例来源:origin: stackoverflow.com

ObjectMapper mapper = new ObjectMapper();
// either via module
mapper.registerModule(new ParanamerModule());
// or by directly assigning annotation introspector (but not both!)
mapper.setAnnotationIntrospector(new ParanamerOnJacksonAnnotationIntrospector());

代码示例来源:origin: org.glassfish.jersey.media/jersey-media-json-jackson

protected final void _setAnnotations(ObjectMapper mapper, Annotations[] annotationsToUse)
  {
    AnnotationIntrospector intr;
    if (annotationsToUse == null || annotationsToUse.length == 0) {
      intr = AnnotationIntrospector.nopInstance();
    } else {
      intr = _resolveIntrospectors(annotationsToUse);
    }
    mapper.setAnnotationIntrospector(intr);
  }
}

代码示例来源:origin: org.springframework.boot/spring-boot-actuator

private void applyConfigurationPropertiesFilter(ObjectMapper mapper) {
  mapper.setAnnotationIntrospector(
      new ConfigurationPropertiesAnnotationIntrospector());
  mapper.setFilterProvider(new SimpleFilterProvider()
      .setDefaultFilter(new ConfigurationPropertiesPropertyFilter()));
}

代码示例来源:origin: org.glassfish.jersey.media/jersey-media-json-jackson

@Override
protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations,
                        final Class<?> defaultView) {
  final AnnotationIntrospector customIntrospector = mapper.getSerializationConfig().getAnnotationIntrospector();
  // Set the custom (user) introspector to be the primary one.
  final ObjectMapper filteringMapper = mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(customIntrospector,
      new JacksonAnnotationIntrospector() {
        @Override
        public Object findFilterId(final Annotated a) {
          final Object filterId = super.findFilterId(a);
          if (filterId != null) {
            return filterId;
          }
          if (a instanceof AnnotatedMethod) {
            final Method method = ((AnnotatedMethod) a).getAnnotated();
            // Interested only in getters - trying to obtain "field" name from them.
            if (ReflectionHelper.isGetter(method)) {
              return ReflectionHelper.getPropertyName(method);
            }
          }
          if (a instanceof AnnotatedField || a instanceof AnnotatedClass) {
            return a.getName();
          }
          return null;
        }
      }));
  return super._configForWriting(filteringMapper, annotations, defaultView);
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-common

public static void configObjectMapper(ObjectMapper mapper) {
 AnnotationIntrospector introspector =
   new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
 mapper.setAnnotationIntrospector(introspector);
 mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-common

private ObjectMapper createObjectMapper() {
 ObjectMapper mapper = new ObjectMapper();
 mapper.setAnnotationIntrospector(
   new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
 mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
 mapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false);
 return mapper;
}

代码示例来源:origin: rancher/cattle

public JacksonJsonMapper() {
  mapper = new ObjectMapper();
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
  AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
  AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
  AnnotationIntrospector pair = AnnotationIntrospectorPair.create(primary, secondary);
  mapper.setAnnotationIntrospector(pair);
}

代码示例来源:origin: com.fasterxml.jackson.jaxrs/jackson-jaxrs-base

protected final void _setAnnotations(ObjectMapper mapper, Annotations[] annotationsToUse)
  {
    AnnotationIntrospector intr;
    if (annotationsToUse == null || annotationsToUse.length == 0) {
      intr = AnnotationIntrospector.nopInstance();
    } else {
      intr = _resolveIntrospectors(annotationsToUse);
    }
    mapper.setAnnotationIntrospector(intr);
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-timeline-pluginstorage

static ObjectMapper createObjectMapper() {
 ObjectMapper mapper = new ObjectMapper();
 mapper.setAnnotationIntrospector(
   new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
 mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
 return mapper;
}

代码示例来源:origin: com.visionarts/masking-json

private void setAnnotationIntrospectors(ObjectMapper mapper) {
    AnnotationIntrospector curSerIntro = mapper.getSerializationConfig().getAnnotationIntrospector();
    AnnotationIntrospector newSerIntro = AnnotationIntrospectorPair.pair(curSerIntro,
        new MaskableSensitiveDataAnnotationIntrospector());
    mapper.setAnnotationIntrospector(newSerIntro);
  }
}

相关文章

微信公众号

最新文章

更多

ObjectMapper类方法