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

项目:eservice    文件:CommonBeans.java   
@Bean(name = "objectMapper")
public ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();

    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JodaModule());
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
        // borrowed from: http://jackson-users.ning.com/forum/topics/how-to-not-include-type-info-during-serialization-with
        @Override
        protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config, Annotated ann, JavaType baseType) {

            // Don't serialize JsonTypeInfo Property includes
            if (ann.hasAnnotation(JsonTypeInfo.class)
                    && ann.getAnnotation(JsonTypeInfo.class).include() == JsonTypeInfo.As.PROPERTY
                    && SerializationConfig.class.isAssignableFrom(config.getClass())) {
                return null;

            }

            return super._findTypeResolver(config, ann, baseType);
        }
    });

    return mapper;
}
项目:steve-plugsurfing    文件:WebSocketConfiguration.java   
@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    mapper.registerModule(new Ocpp12JacksonModule());
    mapper.registerModule(new Ocpp15JacksonModule());

    mapper.setAnnotationIntrospector(
            AnnotationIntrospector.pair(
                    new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector(mapper.getTypeFactory())
            )
    );
    return mapper;
}
项目:factoryfx    文件:HttpServer.java   
ObjectMapper getObjectMapper() {
        ObjectMapper objectMapper = ObjectMapperBuilder.buildNewObjectMapper();
//        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        SimpleModule module = new SimpleModule();
        module.addSerializer(BigDecimal.class, new ToStringSerializer());
        module.addSerializer(Long.class, new ToStringSerializer());
        objectMapper.registerModule(module);

        //Disable JsonIdentityInfo
        JacksonAnnotationIntrospector ignoreJsonTypeInfoIntrospector = new JacksonAnnotationIntrospector() {
            @Override
            public ObjectIdInfo findObjectIdInfo(Annotated ann) {
                return null;
            }
        };
        objectMapper.setAnnotationIntrospector(ignoreJsonTypeInfoIntrospector);

        return objectMapper;
    }
项目:whois    文件:RdapResponseJsonTest.java   
private JsonFactory createJsonFactory() {
    final ObjectMapper objectMapper = new ObjectMapper();

    objectMapper.setAnnotationIntrospector(
            new AnnotationIntrospectorPair(
                    new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector(TypeFactory.defaultInstance())));

    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    objectMapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true);

    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    objectMapper.setDateFormat(df);

    return objectMapper.getFactory();
}
项目:steve    文件:WebSocketConfiguration.java   
@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    mapper.registerModule(new Ocpp12JacksonModule());
    mapper.registerModule(new Ocpp15JacksonModule());

    mapper.setAnnotationIntrospector(
            AnnotationIntrospector.pair(
                    new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector(mapper.getTypeFactory())
            )
    );
    return mapper;
}
项目:camunda-task-dispatcher    文件:JsonTaskMapper.java   
@PostConstruct
public void init() {
    objectMapper = new ObjectMapper()
            .setAnnotationIntrospector(
                    new AnnotationIntrospectorPair(
                            new JaxbAnnotationIntrospector(TypeFactory.defaultInstance())
                            , new JacksonAnnotationIntrospector()
                    )
            )
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
项目:mtgo-best-bot    文件:BotObjectMapper.java   
/**
 * Annotation introspector to use for serialization process
 * is configured separately for serialization and deserialization purposes
 */
public BotObjectMapper() {
    final AnnotationIntrospector introspector
            = new JacksonAnnotationIntrospector();
    super.getDeserializationConfig()
            .with(introspector);
    super.getSerializationConfig()
            .with(introspector);

}
项目:mpd-tools    文件:MPDParser.java   
public static ObjectMapper defaultObjectMapper() {
    return new XmlMapper(new XmlFactory(new WstxInputFactory(), new WstxPrefixedOutputFactory()))
            .enable(SerializationFeature.INDENT_OUTPUT)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
            .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true)
            .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
            .registerModule(new ParserModule())
            .setAnnotationIntrospector(AnnotationIntrospector.pair(
                    new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()),
                    new JacksonAnnotationIntrospector()));
}
项目:jee-demo    文件:PersonDTOTest.java   
@Test
public void testSerializeJSON() throws IOException {

    Person person = new Person();
    person.setId(12345L);
    person.setFirstName("Peter");
    person.setLastName("Walser");
    person.setGender(Gender.MALE);
    person.setDateOfBirth(LocalDate.of(1975, 12, 20));

    StringWriter buffer = new StringWriter();
    ObjectMapper mapper = new ObjectMapper();

    mapper.setAnnotationIntrospector(
            AnnotationIntrospector.pair(
                    new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector(mapper.getTypeFactory())
            )
    );
    mapper.writerWithDefaultPrettyPrinter().writeValue(buffer, person);

    String jsonString = buffer.toString();
    System.out.println(jsonString);

    Assert.assertTrue(jsonString.contains("\"id\" : 12345"));
    Assert.assertTrue(jsonString.contains("\"first_name\" : \"Peter\""));
    Assert.assertTrue(jsonString.contains("\"last_name\" : \"Walser\""));
    Assert.assertTrue(jsonString.contains("\"gender\" : \"MALE\""));
    Assert.assertTrue(jsonString.contains("\"birth_date\" : \"1975-12-20\""));

}
项目: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 = AnnotationIntrospector.pair(
      new ApiAnnotationIntrospector(config), new JacksonAnnotationIntrospector());
  objectMapper.setAnnotationIntrospector(pair);
  return objectMapper;
}
项目:OSHv4    文件:BcontrolSmartMeterDriver.java   
public void receiveHeaterMessageFromMeter(String msg) throws Exception {
        // parse to JSON and send to database

        // Setting up Jackson Tree Model with ObjectMapper
        ObjectMapper om = new ObjectMapper();
        AnnotationIntrospector introspectorJackson = new JacksonAnnotationIntrospector();

        om.setAnnotationIntrospector(introspectorJackson);

        // Retrieve JSON responses from controller and build Jackson Tree
        // Model with package de.fzi.iik.habiteq.jackson
        BcontrolHeaterData bchd = null;
//      try {
            bchd = om.readValue(msg, BcontrolHeaterData.class);
//      } 
//      catch (JsonParseException e) {
//          getGlobalLogger().logWarning(e.getStackTrace(), e);
//      } 
//      catch (JsonMappingException e) {
//          getGlobalLogger().logWarning(e.getStackTrace(), e);
//      } 
//      catch (IOException e) {
//          getGlobalLogger().logWarning(e.getStackTrace(), e);
//      }

//      getGlobalLogger().logDebug(msg);
//      getGlobalLogger().logDebug(bcmd);

        // save to registry
        getDriverRegistry().setStateOfSender(
                BcontrolHeaterDriverRawLogDetails.class, 
                convertJsonToRawDetails(bchd));
    }
项目:Robusto    文件:SpringClientConfiguration.java   
/**
 * Build a default Jackson ObjectMapper. The default implementation is to
 * include non-null, ignore uknown properties on deserialization, and use
 * the date format yyyy-MM-dd'T'HH:mm:ssZ.
 * @return A Jackson ObjectMapper.
 */
protected ObjectMapper buildDefaultJacksonObjectMapper()
{
   /* Cant use unless Spring 4.x is being used throughout
   return new Jackson2ObjectMapperBuilder()
         .serializationInclusion(JsonInclude.Include.NON_NULL)
         .failOnUnknownProperties(false)
         .dateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"))
         .featuresToEnable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)
         .annotationIntrospector(AnnotationIntrospector.pair(
               new JacksonAnnotationIntrospector(),
               new JaxbAnnotationIntrospector()))
         .build();
         */
   ObjectMapper mapper = new ObjectMapper();
   mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
   mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
   mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"));
   mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
   mapper.registerModule(new JodaModule());

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

   return mapper;
}
项目:iem4j    文件:RowSerializer.java   
public RowSerializer(){
    mapper = new ObjectMapper();
    mapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(
            new JacksonAnnotationIntrospector(),
            new JaxbAnnotationIntrospector(mapper.getTypeFactory())
    ));
}
项目:iem4j    文件:RowSerializer.java   
public static RowSerializer getJAXBandJacksonSerializer(){
    RowSerializer serializer = new RowSerializer();
    serializer.mapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(
            new JacksonAnnotationIntrospector(),
            new JaxbAnnotationIntrospector(serializer.mapper.getTypeFactory())
    ));
    return serializer;
}
项目:keystone4j    文件:JacksonProvider.java   
public JacksonProvider() {
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    // if using BOTH JAXB annotations AND Jackson annotations:
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();

    ObjectMapper mapper = new ObjectMapper().registerModule(new Hibernate4Module())
            .setSerializationInclusion(Include.NON_NULL)
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false).enable(SerializationFeature.INDENT_OUTPUT)
            .setAnnotationIntrospector(new AnnotationIntrospectorPair(introspector, secondary));
    // mapper = mapper.setSerializationInclusion(Include)
    setMapper(mapper);
}
项目:keystone4j    文件:ObjectMapperResolver.java   
public ObjectMapperResolver() {
    objectMapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
    objectMapper = objectMapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(introspector, secondary));
    objectMapper = objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper.registerModule(new Hibernate4Module());
}
项目: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;
}
项目:perspective-backend    文件:SerializationUtils.java   
public static ObjectMapper createDefaultMapper() {
    final ObjectMapper result = new ObjectMapper();
    result.configure(SerializationFeature.INDENT_OUTPUT, true);
    result.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    result.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    result.setAnnotationIntrospector(AnnotationIntrospector.pair(
            new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()),
            new JacksonAnnotationIntrospector()
    ));
    return result;
}
项目:PDFReporter-Studio    文件:JacksonHelper.java   
public static ObjectMapper getJSONMapper() {
    ObjectMapper mapper = new ObjectMapper();
    AnnotationIntrospector primary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
    mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary));
    setupMapper(mapper);
    return mapper;
}
项目:PDFReporter-Studio    文件:JacksonHelper.java   
public static XmlMapper getXMLMapper() {
    XmlMapper mapper = new XmlMapper();
    AnnotationIntrospector primary = new XmlJaxbAnnotationIntrospector(mapper.getTypeFactory());
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
    mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary));
    setupMapper(mapper);
    return mapper;
}
项目:Robusto    文件:SpringClientConfiguration.java   
/**
 * Build a default Jackson ObjectMapper. The default implementation is to
 * include non-null, ignore uknown properties on deserialization, and use
 * the date format yyyy-MM-dd'T'HH:mm:ssZ.
 * @return A Jackson ObjectMapper.
 */
protected ObjectMapper buildDefaultJacksonObjectMapper()
{
   /* Cant use unless Spring 4.x is being used throughout
   return new Jackson2ObjectMapperBuilder()
         .serializationInclusion(JsonInclude.Include.NON_NULL)
         .failOnUnknownProperties(false)
         .dateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"))
         .featuresToEnable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)
         .annotationIntrospector(AnnotationIntrospector.pair(
               new JacksonAnnotationIntrospector(),
               new JaxbAnnotationIntrospector()))
         .build();
         */
   ObjectMapper mapper = new ObjectMapper();
   mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
   mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
   mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"));
   mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
   mapper.registerModule(new JodaModule());

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

   return mapper;
}
项目:ean-hotel-api-v3-r29-java-client    文件:ObjectMapperProvider.java   
private static ObjectMapper createObjectMapper() {
    final ObjectMapper om = new ObjectMapper();
    om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    om.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
    om.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    om.setDateFormat(new SimpleDateFormat(DATE_FORMAT));
    om.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
    return om;
}
项目:oap    文件:Binder.java   
private static ObjectMapper initialize( ObjectMapper mapper, boolean defaultTyping, boolean nonNullInclusion ) {
    if( mapper instanceof XmlMapper ) {
        ( ( XmlMapper ) mapper ).setDefaultUseWrapper( false );
    }
    AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
    mapper.getDeserializationConfig().with( introspector );
    mapper.getSerializationConfig().with( introspector );
    mapper.registerModule( new AfterburnerModule() );
    mapper.registerModule( new Jdk8Module().configureAbsentsAsNulls( true ) );
    mapper.registerModule( new JodaModule() );
    mapper.registerModule( new ParameterNamesModule( JsonCreator.Mode.DEFAULT ) );
    mapper.enable( DeserializationFeature.USE_LONG_FOR_INTS );
    mapper.enable( JsonParser.Feature.ALLOW_SINGLE_QUOTES );
    mapper.disable( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES );
    mapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS );
    mapper.disable( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS );
    mapper.disable( SerializationFeature.FAIL_ON_EMPTY_BEANS );
    mapper.configure( JsonGenerator.Feature.AUTO_CLOSE_TARGET, false );
    mapper.setVisibility( PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY );
    if( !nonNullInclusion ) mapper.setSerializationInclusion( JsonInclude.Include.NON_NULL );

    modules.forEach( mapper::registerModule );

    if( defaultTyping )
        mapper.enableDefaultTyping( ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY );

    return mapper;
}
项目: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;
}
项目:api-java-client    文件:StreamClient.java   
private StreamClient(final String endpoint, final String username, final String password,
    final SSLConfiguration sslConfiguration, final Consumer<Event> consumer,
    final Runnable beforeReconnection, final Runnable afterReconnection,
    final boolean reconnect, final int reconnectAttempts,
    final int pauseBeforeReconnectInSeconds)
{
    this.endpoint = checkNotNull(endpoint, "endpoint cannot be null");
    this.username = checkNotNull(username, "username cannot be null");
    this.password = checkNotNull(password, "password cannot be null");
    this.consumer = checkNotNull(consumer, "consumer cannot be null");
    this.sslConfiguration = sslConfiguration;
    this.reconnect = checkNotNull(reconnect);
    if (this.reconnect)
    {
        this.reconnectAttempts = checkNotNull(reconnectAttempts,
            "reconnect attempts cannot be null if reconnection has been enabled");
        this.pauseBeforeReconnectInSeconds = checkNotNull(pauseBeforeReconnectInSeconds,
            "pause seconds before reconnect cannot be null if reconnection has been enabled");
        this.beforeReconnection = beforeReconnection;
        this.afterReconnection = afterReconnection;
    }
    else
    {
        this.beforeReconnection = null;
        this.afterReconnection = null;
    }

    json = new ObjectMapper()
        .setAnnotationIntrospector( //
            new AnnotationIntrospectorPair(new JacksonAnnotationIntrospector(),
                new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()))) //
        .registerModule(new AbiquoModule());
}
项目:cattle    文件:JacksonJsonMapper.java   
public JacksonJsonMapper() {
    SimpleDateFormat df = new SimpleDateFormat(DateUtils.DATE_FORMAT);
    df.setTimeZone(TimeZone.getTimeZone("GMT"));

    mapper = new ObjectMapper();
    mapper.setDateFormat(df);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);

    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    mapper.setAnnotationIntrospector(primary);
}
项目:cloud-cattle    文件:JacksonJsonMapper.java   
public JacksonJsonMapper() {
        mapper = new ObjectMapper();
//        mapper.setSerializationInclusion(Include.NON_NULL);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
        AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());

        AnnotationIntrospector pair = AnnotationIntrospectorPair.create(primary, secondary);
        mapper.setAnnotationIntrospector(pair);
    }
项目:modaclouds-sla-mediator    文件:TierTemplateGenerator.java   
private <T> String toJson(T t) throws JsonProcessingException {
    if (jsonMapper == null) {
        jsonMapper = new ObjectMapper();
        AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
        jsonMapper.getSerializationConfig().with(introspector);
        jsonMapper.setSerializationInclusion(Include.NON_NULL);
    }

    return jsonMapper.writeValueAsString(t);
}
项目:modaclouds-sla-mediator    文件:TemplateGenerator.java   
private <T> String toJson(T t) throws JsonProcessingException {
    if (jsonMapper == null) {
        jsonMapper = new ObjectMapper();
        AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
        jsonMapper.getSerializationConfig().with(introspector);
        jsonMapper.setSerializationInclusion(Include.NON_NULL);
    }

    return jsonMapper.writeValueAsString(t);
}
项目:modaclouds-sla-mediator    文件:Utils.java   
private <E> void printJson(E e) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
//        mapper.getDeserializationConfig().setAnnotationIntrospector(introspector);
        mapper.getSerializationConfig().with(introspector);

        System.out.println(mapper.writeValueAsString(e));
    }
项目:dstack    文件:JacksonJsonMapper.java   
public JacksonJsonMapper() {
        mapper = new ObjectMapper();
//        mapper.setSerializationInclusion(Include.NON_NULL);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
        AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());

        AnnotationIntrospector pair = AnnotationIntrospectorPair.create(primary, secondary);
        mapper.setAnnotationIntrospector(pair);
    }
项目:gedcomx-java    文件:GedcomJacksonModule.java   
/**
 * Creates an object mapper given the specified context classes.
 *
 * @param classes the context classes.
 * @return The object mapper.
 */
public static ObjectMapper createObjectMapper(Class<?>... classes) {
  AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
  ObjectMapper mapper = new ObjectMapper()
    .setAnnotationIntrospector(introspector)
    .enable(SerializationFeature.INDENT_OUTPUT)
    .setSerializationInclusion(JsonInclude.Include.NON_NULL);
  mapper.registerModule(new GedcomJacksonModule());
  for (Class<?> contextClass : classes) {
    GedcomNamespaceManager.registerKnownJsonType(contextClass);
  }
  return mapper;
}
项目:freedomotic    文件:AtmospherePermissionCheckResource.java   
public AtmospherePermissionCheckResource() {
    om = new ObjectMapper();
    // JAXB annotation
    AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
    om.setAnnotationIntrospector(new AnnotationIntrospectorPair(jaxbIntrospector, jacksonIntrospector));
}
项目:freedomotic    文件:AbstractWSResource.java   
public AbstractWSResource() {
    //api = Freedomotic.INJECTOR.getInstance(API.class);
    om = new ObjectMapper();
    // JAXB annotation
    AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
    om.setAnnotationIntrospector(new AnnotationIntrospectorPair(jaxbIntrospector, jacksonIntrospector));

}
项目:partial-response    文件:JacksonFilters.java   
/**
 * Filter all serialised output via the given ObjectMapper with the given matcher.
 */
public static ObjectMapper filterAllOutput(ObjectMapper mapper, Matcher matcher) {
  mapper.setFilters(new SimpleFilterProvider().addFilter(FILTER_ID, new JacksonMatcherFilter(matcher)));
  mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
    @Override
    public Object findFilterId(Annotated a) {
      return FILTER_ID;
    }
  });
  return mapper;
}
项目:track-merger    文件:MergerServiceImpl.java   
@Inject
@SuppressWarnings({ "unchecked", "rawtypes" })
public MergerServiceImpl() {
    JacksonXmlModule module = new JacksonXmlModule();

    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<Enum> modifyEnumDeserializer(
                DeserializationConfig config, final JavaType type, BeanDescription beanDesc,
                final JsonDeserializer<?> deserializer) {
            return new JsonDeserializer<Enum>() {
                @Override
                public Enum deserialize(JsonParser jp, DeserializationContext ctxt)
                        throws IOException {
                    Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
                    return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
                }
            };
        }
    });
    module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
        private static final long serialVersionUID = 4951133737173200158L;

        @Override
        public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider)
                throws IOException {
            jgen.writeString(StringUtils.capitalize(value.name().toLowerCase()));
        }
    });

    // Extra non-JAXB annotations are needed to process abstract classes.
    module.setMixInAnnotation(AbstractSourceT.class, AbstractMixIn.class);

    mapper = new XmlMapper(module);

    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());

    AnnotationIntrospector pair = AnnotationIntrospectorPair.create(primary, secondary);
    mapper.setAnnotationIntrospector(pair);

    SimpleDateFormat sdf = new SimpleDateFormat(Utils.LONG_DATE_FORMAT);
    mapper.setDateFormat(sdf);

    // Serialization options
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    mapper.setSerializationInclusion(Include.NON_NULL);
}
项目:offer    文件:AutoMapper.java   
private AutoMapper() {
  configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
  enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
  setAnnotationIntrospector(new JacksonAnnotationIntrospector());
}
项目:jersey2-restfull-examples    文件:MyObjectMapperProvider.java   
private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector() {
    final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
    return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector);
}
项目:take-a-REST    文件:CustomObjectMapperContextResolver.java   
static ObjectMapper customize(final ObjectMapper mapper) {
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
    mapper.registerModule(new JSR310Module());
    return mapper;
}