Skip to content

Commit

Permalink
Try to reproduce #899
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 14, 2015
1 parent 2e364ba commit 73f54a6
Showing 1 changed file with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.fasterxml.jackson.databind;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.*;
import java.util.*;

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

static enum ABC {
A, B, C;
}

// for [databind#899]
static class EnumPOJO {
public ABC abc = ABC.B;

public Map<String,ABC> stuff = new LinkedHashMap<String,ABC>();
}

/*
/**********************************************************
/* Tests for individual objects
Expand Down Expand Up @@ -63,6 +71,42 @@ public void testConfigs() throws IOException
assertEquals(sc._serFeatures, origSC._serFeatures);
}

// for [databind#899]
public void testEnumHandlers() throws IOException
{
ObjectMapper mapper = new ObjectMapper();
// ensure we have serializers and/or deserializers, first
String json = mapper.writerFor(EnumPOJO.class)
.writeValueAsString(new EnumPOJO());
EnumPOJO result = mapper.reader(EnumPOJO.class)
.readValue(json);
assertNotNull(result);

// and then use JDK serialization to freeze/thaw objects
byte[] bytes = jdkSerialize(mapper);
ObjectMapper mapper2 = jdkDeserialize(bytes);
assertNotNull(mapper2);

bytes = jdkSerialize(mapper.reader(EnumPOJO.class));
ObjectReader r = jdkDeserialize(bytes);
assertNotNull(r);

/* 14-Aug-2015, tatu: Looks like pre-loading JsonSerializer is problematic
* at this point; comment out for now. Try to fix later on.
*/

// bytes = jdkSerialize(mapper.writerFor(EnumPOJO.class));
bytes = jdkSerialize(mapper.writer());
ObjectWriter w = jdkDeserialize(bytes);
assertNotNull(w);

// plus, ensure objects are usable:
String json2 = w.writeValueAsString(new EnumPOJO());
assertEquals(json, json2);
EnumPOJO result2 = r.readValue(json2);
assertNotNull(result2);
}

public void testObjectWriter() throws IOException
{
ObjectWriter origWriter = MAPPER.writer();
Expand Down

0 comments on commit 73f54a6

Please sign in to comment.