Java 类org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector 实例源码

项目:test-html-generator-plugin    文件:Testi.java   
public static void main(String[] args) throws JsonMappingException {
    ObjectMapper jsonMapper = new ObjectMapper();
    AnnotationIntrospector introspector = new AnnotationIntrospector.Pair(new JaxbAnnotationIntrospector(), 
            new JacksonAnnotationIntrospector());
    jsonMapper.setAnnotationIntrospector(introspector);
    JsonSchema schema = jsonMapper.generateJsonSchema(Testi.class);
    if(Testi.class.getAnnotation(XmlRootElement.class)!=null
            && !Testi.class.getAnnotation(XmlRootElement.class).name().equals("##default"))
        schema.getSchemaNode().put("name", Testi.class.getAnnotation(XmlRootElement.class).name());
    else if(Testi.class.getAnnotation(XmlType.class)!=null
            && !Testi.class.getAnnotation(XmlType.class).name().equals("##default"))
        schema.getSchemaNode().put("name", Testi.class.getAnnotation(XmlType.class).name());
    else
        schema.getSchemaNode().put("name", Testi.class.getSimpleName());
    String schemaJson = schema.toString();
    System.out.println(schemaJson);
}
项目:SimpleJavaWS    文件:ServiceConfiguration.java   
@Bean(name="defaultObjectMapper")
public ObjectMapper getObjectMapper() {
    if(defaultObjectMapper==null) {
        ObjectMapper mapper = new ObjectMapper();
        AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
        AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
        AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
        mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
        mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.getSerializationConfig().setAnnotationIntrospector(pair);
        mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
        mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
        this.defaultObjectMapper = mapper;
    }
    return defaultObjectMapper;
}
项目:artifactory    文件:JacksonFactory.java   
/**
 * Update the generator with a default codec and pretty printer
 *
 * @param jsonFactory   Factory to set as codec
 * @param jsonGenerator Generator to configure
 */
private static void updateGenerator(JsonFactory jsonFactory, JsonGenerator jsonGenerator) {
    ObjectMapper mapper = new ObjectMapper(jsonFactory);

    //Update the annotation interceptor to also include jaxb annotations as a second choice
    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector() {

        /**
         * BUG FIX:
         * By contract, if findSerializationInclusion didn't encounter any annotations that should change the
         * inclusion value, it should return the default value it has received; but actually returns null, which
         * overrides the NON_NULL option we set.
         * The doc states issue JACKSON-256 which was supposed to be fixed in 1.5.0. *twilight zone theme song*
         */

        @Override
        public JsonSerialize.Inclusion findSerializationInclusion(Annotated a, JsonSerialize.Inclusion defValue) {
            JsonSerialize.Inclusion inclusion = super.findSerializationInclusion(a, defValue);
            if (inclusion == null) {
                return defValue;
            }
            return inclusion;
        }
    };
    AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
    mapper.getSerializationConfig().setAnnotationIntrospector(pair);
    mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);

    jsonGenerator.setCodec(mapper);
    jsonGenerator.useDefaultPrettyPrinter();
}
项目:artifactory    文件:JacksonFactory.java   
/**
 * Update the parser with a default codec
 *
 * @param jsonFactory Factory to set as codec
 * @param jsonParser  Parser to configure
 */
private static void updateParser(JsonFactory jsonFactory, JsonParser jsonParser) {
    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
    AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);

    ObjectMapper mapper = new ObjectMapper(jsonFactory);
    mapper.getSerializationConfig().setAnnotationIntrospector(pair);
    mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
    mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
    jsonParser.setCodec(mapper);
}
项目:artifactory    文件:JsonProvider.java   
public JsonProvider() {
    ObjectMapper mapper = getMapper();
    //Update the annotation interceptor to also include jaxb annotations as a second choice
    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
    AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);

    mapper.getSerializationConfig().setAnnotationIntrospector(pair);
    mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);

    mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
    //Ignore missing properties
    mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
}
项目:cirrus    文件:JacksonJaxbContextResolver.java   
public JacksonJaxbContextResolver() {
    this.objectMapper = new ObjectMapper();
    final AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    final AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
    final AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);

    this.objectMapper.getDeserializationConfig().setAnnotationIntrospector(pair);
    this.objectMapper.getSerializationConfig().setAnnotationIntrospector(pair);
}
项目:Cassandra-rate-limiting-demo    文件:ObjectMapperFactoryBean.java   
public ObjectMapperFactoryBean() {
    this.objectMapper = new ObjectMapper();
    this.objectMapper.setSerializationInclusion(Inclusion.NON_NULL);
    this.objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
    AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);

    this.objectMapper.setAnnotationIntrospector(pair);
}
项目:incubator-slider    文件:SliderJacksonJaxbJsonProvider.java   
@Override
public ObjectMapper locateMapper(Class<?> type, MediaType mediaType) {
  ObjectMapper mapper = super.locateMapper(type, mediaType);
  AnnotationIntrospector introspector = new AnnotationIntrospector.Pair(
      new JaxbAnnotationIntrospector(),
      new JacksonAnnotationIntrospector()
  );
  mapper.setAnnotationIntrospector(introspector);
  //mapper.setSerializationInclusion(Inclusion.NON_NULL);
  return mapper;
}
项目:oxCore    文件:Util.java   
/**
 * Creates json mapper.
 *
 * @return json mapper
 */
public static ObjectMapper createJsonMapper() {
    final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector();
    final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();

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

    final ObjectMapper mapper = new ObjectMapper();
    mapper.getDeserializationConfig().withAnnotationIntrospector(pair);
    mapper.getSerializationConfig().withAnnotationIntrospector(pair);
    return mapper;
}
项目:oxAuth    文件:ServerUtil.java   
public static ObjectMapper createJsonMapper() {
    final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector();
    final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();

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

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

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

    final ObjectMapper mapper = new ObjectMapper();
    mapper.getDeserializationConfig().withAnnotationIntrospector(pair);
    mapper.getSerializationConfig().withAnnotationIntrospector(pair);
    return mapper;
}
项目:scheduling    文件:JacksonProvider.java   
public JacksonProvider() {
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
    mapper.setAnnotationIntrospector(new AnnotationIntrospector.Pair(introspector, secondary));
    mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
}
项目:cloud-pos-router    文件:ConfigureJackson.java   
private static Pair createJaxbJacksonAnnotationIntrospector() {

        AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector();
        AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();

        return new AnnotationIntrospector.Pair(jacksonIntrospector, jaxbIntrospector);
    }