Skip to content

Commit 57f5e70

Browse files
committed
yet more cleaning of tests
1 parent 24a73d7 commit 57f5e70

File tree

4 files changed

+38
-49
lines changed

4 files changed

+38
-49
lines changed

src/test/java/com/fasterxml/jackson/databind/jsontype/DefaultTypingWithPrimitivesTest.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/test/java/com/fasterxml/jackson/databind/jsontype/deftyping/TestDefaultForEnums.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void testSimpleEnumsInObjectArray() throws Exception
5757

5858
// Typing is needed for enums
5959
String json = m.writeValueAsString(new Object[] { TestEnum.A });
60-
assertEquals("[[\"com.fasterxml.jackson.databind.jsontype.TestDefaultForEnums$TestEnum\",\"A\"]]", json);
60+
assertEquals("[[\"com.fasterxml.jackson.databind.jsontype.deftyping.TestDefaultForEnums$TestEnum\",\"A\"]]", json);
6161

6262
// and let's verify we get it back ok as well:
6363
Object[] value = m.readValue(json, Object[].class);
@@ -70,7 +70,7 @@ public void testSimpleEnumsAsField() throws Exception
7070
ObjectMapper m = new ObjectMapper();
7171
m.enableDefaultTyping();
7272
String json = m.writeValueAsString(new EnumHolder(TestEnum.B));
73-
assertEquals("{\"value\":[\"com.fasterxml.jackson.databind.jsontype.TestDefaultForEnums$TestEnum\",\"B\"]}", json);
73+
assertEquals("{\"value\":[\"com.fasterxml.jackson.databind.jsontype.deftyping.TestDefaultForEnums$TestEnum\",\"B\"]}", json);
7474
EnumHolder holder = m.readValue(json, EnumHolder.class);
7575
assertSame(TestEnum.B, holder.value);
7676
}

src/test/java/com/fasterxml/jackson/databind/jsontype/deftyping/TestDefaultForObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public void testFeature432() throws Exception
337337
ObjectMapper mapper = new ObjectMapper();
338338
mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, "*CLASS*");
339339
String json = mapper.writeValueAsString(new BeanHolder(new StringBean("punny")));
340-
assertEquals("{\"bean\":{\"*CLASS*\":\"com.fasterxml.jackson.databind.jsontype.TestDefaultForObject$StringBean\",\"name\":\"punny\"}}", json);
340+
assertEquals("{\"bean\":{\"*CLASS*\":\"com.fasterxml.jackson.databind.jsontype.deftyping.TestDefaultForObject$StringBean\",\"name\":\"punny\"}}", json);
341341
}
342342

343343
public void testNoGoWithExternalProperty() throws Exception

src/test/java/com/fasterxml/jackson/databind/jsontype/deftyping/TestDefaultForScalars.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
import static org.junit.Assert.*;
66

7+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
78
import com.fasterxml.jackson.databind.*;
9+
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
810

911
/**
1012
* Unit tests to verify that Java/JSON scalar values (non-structured values)
@@ -18,9 +20,14 @@ static class Jackson417Bean {
1820
public java.io.Serializable bar = new Integer(13);
1921
}
2022

23+
// [databind#1395]: prevent attempts at including type info for primitives
24+
static class Data {
25+
public long key;
26+
}
27+
2128
/*
2229
/**********************************************************
23-
/* Unit tests
30+
/* Test methods
2431
/**********************************************************
2532
*/
2633

@@ -92,9 +99,6 @@ public void testScalarArrays() throws Exception
9299
assertArrayEquals(input, output);
93100
}
94101

95-
/**
96-
* Loosely scalar; for [JACKSON-417]
97-
*/
98102
public void test417() throws Exception
99103
{
100104
ObjectMapper m = new ObjectMapper();
@@ -105,4 +109,31 @@ public void test417() throws Exception
105109
assertEquals(input.foo, result.foo);
106110
assertEquals(input.bar, result.bar);
107111
}
112+
113+
// [databind#1395]: prevent attempts at including type info for primitives
114+
public void testDefaultTypingWithLong() throws Exception
115+
{
116+
Data data = new Data();
117+
data.key = 1L;
118+
Map<String, Object> mapData = new HashMap<String, Object>();
119+
mapData.put("longInMap", 2L);
120+
mapData.put("longAsField", data);
121+
122+
// Configure Jackson to preserve types
123+
ObjectMapper mapper = new ObjectMapper();
124+
StdTypeResolverBuilder resolver = new StdTypeResolverBuilder();
125+
resolver.init(JsonTypeInfo.Id.CLASS, null);
126+
resolver.inclusion(JsonTypeInfo.As.PROPERTY);
127+
resolver.typeProperty("__t");
128+
mapper.setDefaultTyping(resolver);
129+
mapper.enable(SerializationFeature.INDENT_OUTPUT);
130+
131+
// Serialize
132+
String json = mapper.writeValueAsString(mapData);
133+
134+
// Deserialize
135+
Map<?,?> result = mapper.readValue(json, Map.class);
136+
assertNotNull(result);
137+
assertEquals(2, result.size());
138+
}
108139
}

0 commit comments

Comments
 (0)