public FoxtrotResourceTest() throws Exception { getObjectMapperFactory().setSerializationInclusion(JsonInclude.Include.NON_NULL); getObjectMapperFactory().setSerializationInclusion(JsonInclude.Include.NON_EMPTY); SubtypeResolver subtypeResolver = new StdSubtypeResolver(); getObjectMapperFactory().setSubtypeResolver(subtypeResolver); getObjectMapperFactory().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); this.mapper = getObjectMapperFactory().build(); this.dataStore = TestUtils.getDataStore(); //Initializing Cache Factory hazelcastInstance = new TestHazelcastInstanceFactory(1).newHazelcastInstance(); HazelcastConnection hazelcastConnection = Mockito.mock(HazelcastConnection.class); when(hazelcastConnection.getHazelcast()).thenReturn(hazelcastInstance); this.cacheManager = new CacheManager(new DistributedCacheFactory(hazelcastConnection, mapper)); elasticsearchServer = new MockElasticsearchServer(UUID.randomUUID().toString()); ElasticsearchConnection elasticsearchConnection = Mockito.mock(ElasticsearchConnection.class); when(elasticsearchConnection.getClient()).thenReturn(elasticsearchServer.getClient()); ElasticsearchUtils.initializeMappings(elasticsearchServer.getClient()); Settings indexSettings = ImmutableSettings.settingsBuilder().put("number_of_replicas", 0).build(); CreateIndexRequest createRequest = new CreateIndexRequest(TableMapStore.TABLE_META_INDEX).settings(indexSettings); elasticsearchServer.getClient().admin().indices().create(createRequest).actionGet(); elasticsearchServer.getClient().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); tableMetadataManager = Mockito.mock(TableMetadataManager.class); tableMetadataManager.start(); this.queryStore = new ElasticsearchQueryStore(tableMetadataManager, elasticsearchConnection, dataStore, mapper); this.queryStore = spy(queryStore); AnalyticsLoader analyticsLoader = new AnalyticsLoader(tableMetadataManager, dataStore, queryStore, elasticsearchConnection, cacheManager, mapper); analyticsLoader.start(); TestUtils.registerActions(analyticsLoader, mapper); ExecutorService executorService = Executors.newFixedThreadPool(1); queryExecutor = new QueryExecutor(analyticsLoader, executorService); }
/** * Constructs instance that uses specified {@link JsonFactory} * for constructing necessary {@link JsonParser}s and/or * {@link JsonGenerator}s, and uses given providers for accessing * serializers and deserializers. * * @param jf JsonFactory to use: if null, a new {@link MappingJsonFactory} will be constructed * @param sp SerializerProvider to use: if null, a {@link SerializerProvider} will be constructed * @param dc Blueprint deserialization context instance to use for creating * actual context objects; if null, will construct standard * {@link DeserializationContext} */ public ObjectMapper(JsonFactory jf, DefaultSerializerProvider sp, DefaultDeserializationContext dc) { /* 02-Mar-2009, tatu: Important: we MUST default to using * the mapping factory, otherwise tree serialization will * have problems with POJONodes. * 03-Jan-2010, tatu: and obviously we also must pass 'this', * to create actual linking. */ if (jf == null) { _jsonFactory = new MappingJsonFactory(this); } else { _jsonFactory = jf; if (jf.getCodec() == null) { // as per [JACKSON-741] _jsonFactory.setCodec(this); } } _subtypeResolver = new StdSubtypeResolver(); _rootNames = new RootNameLookup(); // and default type factory is shared one _typeFactory = TypeFactory.defaultInstance(); _serializationConfig = new SerializationConfig(DEFAULT_BASE, _subtypeResolver, _mixInAnnotations); _deserializationConfig = new DeserializationConfig(DEFAULT_BASE, _subtypeResolver, _mixInAnnotations); _serializerProvider = (sp == null) ? new DefaultSerializerProvider.Impl() : sp; _deserializationContext = (dc == null) ? new DefaultDeserializationContext.Impl(BeanDeserializerFactory.instance) : dc; // Default serializer factory is stateless, can just assign _serializerFactory = BeanSerializerFactory.instance; }
private void configureObjectMapper(Environment environment) { environment.getObjectMapperFactory().setSerializationInclusion(JsonInclude.Include.NON_NULL); environment.getObjectMapperFactory().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); SubtypeResolver subtypeResolver = new StdSubtypeResolver(); environment.getObjectMapperFactory().setSubtypeResolver(subtypeResolver); }