Merge branch '2.0.x'
This commit is contained in:
@@ -17,10 +17,14 @@
|
||||
package org.springframework.cloud.bus.jackson;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -46,7 +50,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT,
|
||||
properties = "spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS:true")
|
||||
public class BusJacksonIntegrationTests {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -59,9 +64,18 @@ public class BusJacksonIntegrationTests {
|
||||
private BusJacksonMessageConverter converter;
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testCustomEventSerializes() {
|
||||
assertThat(this.converter.isMapperCreated()).isFalse();
|
||||
|
||||
// set by configuration
|
||||
assertThat(this.converter.getMapper().getSerializationConfig()
|
||||
.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)).isTrue();
|
||||
|
||||
Map map = this.rest.getForObject("http://localhost:" + this.port + "/date", Map.class);
|
||||
assertThat(map).containsOnlyKeys("date");
|
||||
assertThat(map.get("date")).isInstanceOf(Long.class);
|
||||
|
||||
this.rest.put("http://localhost:" + this.port + "/names" + "/foo", null);
|
||||
this.rest.put("http://localhost:" + this.port + "/names" + "/bar", null);
|
||||
|
||||
@@ -119,6 +133,13 @@ public class BusJacksonIntegrationTests {
|
||||
new NameEvent(this, this.busServiceMatcher.getServiceId(), name));
|
||||
}
|
||||
|
||||
@GetMapping("/date")
|
||||
public Map<String, Object> testTimeJsonSerialization(){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("date", new Date());
|
||||
return map;
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handleNameSaid(NameEvent event) {
|
||||
this.names.add(event.getName());
|
||||
|
||||
@@ -105,10 +105,14 @@ class BusJacksonMessageConverter extends AbstractMessageConverter
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMapperCreated() {
|
||||
/* for testing */ boolean isMapperCreated() {
|
||||
return this.mapperCreated;
|
||||
}
|
||||
|
||||
/* for testing */ ObjectMapper getMapper() {
|
||||
return this.mapper;
|
||||
}
|
||||
|
||||
public void setPackagesToScan(String[] packagesToScan) {
|
||||
List<String> packages = new ArrayList<>(Arrays.asList(packagesToScan));
|
||||
if (!packages.contains(DEFAULT_PACKAGE)) {
|
||||
@@ -190,7 +194,6 @@ class BusJacksonMessageConverter extends AbstractMessageConverter
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
this.mapper.registerModule(new SubtypeModule(findSubTypes()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user