Skip to content

Commit

Permalink
Fix #749
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 25, 2015
1 parent 279e386 commit ed7d416
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Project: jackson-databind

2.6.3 (not yet released)

#749: `EnumMap` serialization ignores `SerializationFeature.WRITE_ENUMS_USING_TO_STRING`
(reported by scubasau@github)
#938: Regression: `StackOverflowError` with recursive types that contain `Map.Entry`
(reported by jloisel@github)
#940: Add missing `hashCode()` implementations for `JsonNode` types that did not have them
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.databind.ser;
package com.fasterxml.jackson.databind.misc;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.type.TypeFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import java.io.*;
import java.util.*;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
Expand Down Expand Up @@ -207,6 +205,14 @@ public void serialize(Foo661 value, JsonGenerator jgen, SerializerProvider provi
}
}
}

protected static enum LC749Enum {
A, B, C;
private LC749Enum() { }
@Override
public String toString() { return name().toLowerCase(); }
}

/*
/**********************************************************
/* Tests
Expand Down Expand Up @@ -384,6 +390,31 @@ public void testCustomEnumMapKeySerializer() throws Exception {
String json = MAPPER.writeValueAsString(new MyBean661("abc"));
assertEquals(aposToQuotes("{'X-FOO':'abc'}"), json);
}

// [databind#749]

public void testEnumMapSerDefault() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
EnumMap<LC749Enum, String> m = new EnumMap<LC749Enum, String>(LC749Enum.class);
m.put(LC749Enum.A, "value");
assertEquals("{\"A\":\"value\"}", mapper.writeValueAsString(m));
}

public void testEnumMapSerDisableToString() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
ObjectWriter w = mapper.writer().without(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
EnumMap<LC749Enum, String> m = new EnumMap<LC749Enum, String>(LC749Enum.class);
m.put(LC749Enum.A, "value");
assertEquals("{\"A\":\"value\"}", w.writeValueAsString(m));
}

public void testEnumMapSerEnableToString() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
ObjectWriter w = mapper.writer().with(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
EnumMap<LC749Enum, String> m = new EnumMap<LC749Enum, String>(LC749Enum.class);
m.put(LC749Enum.A, "value");
assertEquals("{\"a\":\"value\"}", w.writeValueAsString(m));
}
}

// [JACKSON-757], non-inner enum
Expand Down

0 comments on commit ed7d416

Please sign in to comment.