类com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector源码实例Demo

下面列出了怎么用com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: endpoints-java   文件: ObjectMapperUtil.java
/**
 * Creates an Endpoints standard object mapper that allows unquoted field names and unknown
 * properties.
 *
 * Note on unknown properties: When Apiary FE supports a strict mode where properties
 * are checked against the schema, BE can just ignore unknown properties.  This way, FE does
 * not need to filter out everything that the BE doesn't understand.  Before that's done,
 * a property name with a typo in it, for example, will just be ignored by the BE.
 */
public static ObjectMapper createStandardObjectMapper(ApiSerializationConfig config) {
  ObjectMapper objectMapper = new ObjectMapper()
      .configure(JsonParser.Feature.ALLOW_COMMENTS, true)
      .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
      .configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
      .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
      .setBase64Variant(Base64Variants.MODIFIED_FOR_URL)
      .setSerializerFactory(
          BeanSerializerFactory.instance.withSerializerModifier(new DeepEmptyCheckingModifier()));
  AnnotationIntrospector pair = EndpointsFlag.JSON_USE_JACKSON_ANNOTATIONS.isEnabled()
      ? AnnotationIntrospector.pair(
          new ApiAnnotationIntrospector(config),
          new JacksonAnnotationIntrospector())
      : new ApiAnnotationIntrospector(config);
  objectMapper.setAnnotationIntrospector(pair);
  return objectMapper;
}
 
源代码2 项目: jackson-modules-base   文件: ObjectMapperModule.java
@Override
public ObjectMapper get()
{
    ObjectMapper mapper = objectMapper;
    if (mapper == null) {
        final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector();
        AnnotationIntrospector defaultAI = new JacksonAnnotationIntrospector();
        MapperBuilder<?,?> builder = JsonMapper.builder()
                .injectableValues(new GuiceInjectableValues(injector))
                .annotationIntrospector(new AnnotationIntrospectorPair(guiceIntrospector, defaultAI))
                .addModules(modulesToAdd);
        for (Provider<? extends Module> provider : providedModules) {
            builder = builder.addModule(provider.get());
        }
        mapper = builder.build();

      /*
  } else {
        // 05-Feb-2017, tatu: _Should_ be fine, considering instances are now (3.0) truly immutable.
      //    But if this turns out to be problematic, may need to consider addition of `copy()`
      //    back in databind
      mapper = mapper.copy();
      */
  }
  return mapper;
}
 
源代码3 项目: jackson-modules-base   文件: TestJaxbAutoDetect.java
public void testJaxbAnnotatedObject() throws Exception
{
    AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary);
    ObjectMapper mapper = objectMapperBuilder()
            .annotationIntrospector(pair)
            .build();

    JaxbAnnotatedObject original = new JaxbAnnotatedObject("123");
    
    String json = mapper.writeValueAsString(original);
    assertFalse("numberString field in JSON", json.contains("numberString")); // kinda hack-y :)
    JaxbAnnotatedObject result = mapper.readValue(json, JaxbAnnotatedObject.class);
    assertEquals(new BigDecimal("123"), result.number);
}
 
源代码4 项目: jackson-modules-base   文件: TestUnwrapping.java
public void testXmlElementAndXmlElementRefs() throws Exception
    {
        Bean<A> bean = new Bean<A>();
        bean.r = new A(12);
        bean.name = "test";
        AnnotationIntrospector pair = new AnnotationIntrospectorPair(
                new JacksonAnnotationIntrospector(),
                new JaxbAnnotationIntrospector());
        ObjectMapper mapper = objectMapperBuilder()
                .annotationIntrospector(pair)
                .build();
            
//            mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
            // mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());

        String json = mapper.writeValueAsString(bean);
        // !!! TODO: verify
        assertNotNull(json);
    }
 
@Bean
public ObjectMapper firebaseObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
        @Override
        public boolean hasIgnoreMarker(AnnotatedMember m) {
            return _findAnnotation(m, FirebaseId.class) != null;
        }
    });
    return objectMapper;
}
 
@Override
public void init(EndpointConfig config) {
    mapper = new ObjectMapper();
    mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
    mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector(mapper.getTypeFactory())));
    // Don't close the output stream
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    // Don't include NULL properties.
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
 
源代码7 项目: datawave   文件: JacksonContextResolver.java
public JacksonContextResolver() {
    mapper = new ObjectMapper();
    mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
    mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector(mapper.getTypeFactory())));
    mapper.setSerializationInclusion(Include.NON_NULL);
}
 
源代码8 项目: shopify-sdk   文件: ShopifySdkObjectMapper.java
public static ObjectMapper buildMapper() {
	final ObjectMapper mapper = new ObjectMapper();
	mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

	final AnnotationIntrospector pair = AnnotationIntrospector.pair(
			new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()), new JacksonAnnotationIntrospector());
	mapper.setAnnotationIntrospector(pair);

	mapper.enable(MapperFeature.USE_ANNOTATIONS);
	return mapper;
}
 
源代码9 项目: conjure   文件: ConjureParser.java
@VisibleForTesting
static ObjectMapper createConjureParserObjectMapper() {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory())
            .registerModule(new Jdk8Module())
            .setAnnotationIntrospector(AnnotationIntrospector.pair(
                    new KebabCaseEnforcingAnnotationInspector(), // needs to come first.
                    new JacksonAnnotationIntrospector()));
    mapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
    return mapper;
}
 
源代码10 项目: hermes   文件: ObjectMapperProvider.java
private static ObjectMapper createDefaultMapper() {
	AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
	ObjectMapper result = new ObjectMapper();
	result.configure(SerializationFeature.INDENT_OUTPUT, true);
	result.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
	result.getDeserializationConfig().withInsertedAnnotationIntrospector(jacksonIntrospector);
	result.getSerializationConfig().withInsertedAnnotationIntrospector(jacksonIntrospector);
	return result;
}
 
源代码11 项目: jackson-modules-base   文件: BaseJaxbTest.java
protected MapperBuilder<?,?> getJaxbAndJacksonMapperBuilder()
{
    return JsonMapper.builder()
            .annotationIntrospector(new AnnotationIntrospectorPair(
                    new JaxbAnnotationIntrospector(),
                    new JacksonAnnotationIntrospector()));
}
 
源代码12 项目: proarc   文件: JsonUtils.java
/**
 * Creates a configured mapper supporting JAXB.
 * @see #createObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)
 */
public static ObjectMapper createJaxbMapper() {
    ObjectMapper om = createObjectMapper(createObjectMapper());
    JaxbAnnotationIntrospector jaxbIntr = new JaxbAnnotationIntrospector(om.getTypeFactory());
    JacksonAnnotationIntrospector jsonIntr = new JacksonAnnotationIntrospector();
    om.setAnnotationIntrospector(new AnnotationIntrospectorPair(jsonIntr, jaxbIntr));
    return om;
}
 
源代码13 项目: oxAuth   文件: ServerUtil.java
public static ObjectMapper createJsonMapper() {
    final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector();
    final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();

    final AnnotationIntrospector pair = AnnotationIntrospector.pair(jackson, jaxb);

    final ObjectMapper mapper = new ObjectMapper();
    mapper.getDeserializationConfig().with(pair);
    mapper.getSerializationConfig().with(pair);
    return mapper;
}
 
源代码14 项目: oxAuth   文件: Util.java
public static ObjectMapper createJsonMapper() {
    final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector();
    final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();

    final AnnotationIntrospector pair = AnnotationIntrospector.pair(jackson, jaxb);

    final ObjectMapper mapper = new ObjectMapper();
    mapper.getDeserializationConfig().with(pair);
    mapper.getSerializationConfig().with(pair);
    return mapper;
}
 
源代码15 项目: oxd   文件: Jackson2.java
public static ObjectMapper jsonMapper() {
    final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();

    final ObjectMapper mapper = new ObjectMapper();
    final DeserializationConfig deserializationConfig = mapper.getDeserializationConfig().with(jackson);
    final SerializationConfig serializationConfig = mapper.getSerializationConfig().with(jackson);
    if (deserializationConfig != null && serializationConfig != null) {
        // do nothing for now
    }
    return mapper;
}
 
源代码16 项目: attic-rave   文件: JsonUtils.java
private static ObjectMapper getMapper() {
    ObjectMapper jacksonMapper = new ObjectMapper();
    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    jacksonMapper.setAnnotationIntrospector(primary);
    jacksonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    jacksonMapper.registerModule(new MrBeanModule());
    return jacksonMapper;
}
 
源代码17 项目: jackson-modules-base   文件: BaseJaxbTest.java
protected MapperBuilder<?,?> getJacksonAndJaxbMapperBuilder()
{
    return JsonMapper.builder()
            .annotationIntrospector(new AnnotationIntrospectorPair(new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector()));
}
 
 同包方法