Skip to content

Commit 73f54a6

Browse files
committed
Try to reproduce #899
1 parent 2e364ba commit 73f54a6

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

src/test/java/com/fasterxml/jackson/databind/TestJDKSerialization.java

+49-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.fasterxml.jackson.databind;
22

3-
import java.io.ByteArrayInputStream;
4-
import java.io.ByteArrayOutputStream;
5-
import java.io.IOException;
6-
import java.io.ObjectInputStream;
7-
import java.io.ObjectOutputStream;
3+
import java.io.*;
4+
import java.util.*;
85

96
import com.fasterxml.jackson.databind.type.TypeFactory;
107
import com.fasterxml.jackson.databind.util.LRUMap;
@@ -31,6 +28,17 @@ public MyPojo(int x0, int y0) {
3128
public void setY(int y) { this.y = y; }
3229
}
3330

31+
static enum ABC {
32+
A, B, C;
33+
}
34+
35+
// for [databind#899]
36+
static class EnumPOJO {
37+
public ABC abc = ABC.B;
38+
39+
public Map<String,ABC> stuff = new LinkedHashMap<String,ABC>();
40+
}
41+
3442
/*
3543
/**********************************************************
3644
/* Tests for individual objects
@@ -63,6 +71,42 @@ public void testConfigs() throws IOException
6371
assertEquals(sc._serFeatures, origSC._serFeatures);
6472
}
6573

74+
// for [databind#899]
75+
public void testEnumHandlers() throws IOException
76+
{
77+
ObjectMapper mapper = new ObjectMapper();
78+
// ensure we have serializers and/or deserializers, first
79+
String json = mapper.writerFor(EnumPOJO.class)
80+
.writeValueAsString(new EnumPOJO());
81+
EnumPOJO result = mapper.reader(EnumPOJO.class)
82+
.readValue(json);
83+
assertNotNull(result);
84+
85+
// and then use JDK serialization to freeze/thaw objects
86+
byte[] bytes = jdkSerialize(mapper);
87+
ObjectMapper mapper2 = jdkDeserialize(bytes);
88+
assertNotNull(mapper2);
89+
90+
bytes = jdkSerialize(mapper.reader(EnumPOJO.class));
91+
ObjectReader r = jdkDeserialize(bytes);
92+
assertNotNull(r);
93+
94+
/* 14-Aug-2015, tatu: Looks like pre-loading JsonSerializer is problematic
95+
* at this point; comment out for now. Try to fix later on.
96+
*/
97+
98+
// bytes = jdkSerialize(mapper.writerFor(EnumPOJO.class));
99+
bytes = jdkSerialize(mapper.writer());
100+
ObjectWriter w = jdkDeserialize(bytes);
101+
assertNotNull(w);
102+
103+
// plus, ensure objects are usable:
104+
String json2 = w.writeValueAsString(new EnumPOJO());
105+
assertEquals(json, json2);
106+
EnumPOJO result2 = r.readValue(json2);
107+
assertNotNull(result2);
108+
}
109+
66110
public void testObjectWriter() throws IOException
67111
{
68112
ObjectWriter origWriter = MAPPER.writer();

0 commit comments

Comments
 (0)