Auto-detect Kotlin Jackson module
Issue: SPR-14108
This commit is contained in:
@@ -65,6 +65,7 @@ import com.fasterxml.jackson.databind.ser.std.NumberSerializer;
|
||||
import com.fasterxml.jackson.databind.type.SimpleType;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
|
||||
import kotlin.ranges.IntRange;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Test;
|
||||
@@ -255,6 +256,10 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
|
||||
Optional<String> optional = Optional.of("test");
|
||||
assertEquals("\"test\"", new String(objectMapper.writeValueAsBytes(optional), "UTF-8"));
|
||||
|
||||
// Kotlin module
|
||||
IntRange range = new IntRange(1, 3);
|
||||
assertEquals("{\"start\":1,\"end\":3}", new String(objectMapper.writeValueAsBytes(range), "UTF-8"));
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
@@ -328,8 +333,8 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
Class<?> target = String.class;
|
||||
Class<?> mixInSource = Object.class;
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().mixIn(target,
|
||||
mixInSource).build();
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules()
|
||||
.mixIn(target, mixInSource).build();
|
||||
|
||||
assertEquals(1, objectMapper.mixInCount());
|
||||
assertSame(mixInSource, objectMapper.findMixInClassFor(target));
|
||||
@@ -342,7 +347,8 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
Map<Class<?>, Class<?>> mixIns = new HashMap<Class<?>, Class<?>>();
|
||||
mixIns.put(target, mixInSource);
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().mixIns(mixIns).build();
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules()
|
||||
.mixIns(mixIns).build();
|
||||
|
||||
assertEquals(1, objectMapper.mixInCount());
|
||||
assertSame(mixInSource, objectMapper.findMixInClassFor(target));
|
||||
|
||||
@@ -285,6 +285,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
|
||||
Map<Class<?>, Class<?>> mixIns = new HashMap<Class<?>, Class<?>>();
|
||||
mixIns.put(target, mixinSource);
|
||||
|
||||
this.factory.setModules(Collections.emptyList());
|
||||
this.factory.setMixIns(mixIns);
|
||||
this.factory.afterPropertiesSet();
|
||||
ObjectMapper objectMapper = this.factory.getObject();
|
||||
|
||||
Reference in New Issue
Block a user