Skip to content

Commit

Permalink
add failing test for #1429
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 24, 2016
1 parent b9904fa commit 9257bd6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static KeyType create(String v) {
}
}

// Issue #142
// [databind#142]
public static class EnumMapContainer {
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
public EnumMap<KeyEnum,ITestType> testTypes;
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/com/fasterxml/jackson/failing/KeyDeser1429Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.fasterxml.jackson.failing;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;

public class KeyDeser1429Test extends BaseMapTest
{
static class FullName {
private String _firstname, _lastname;

private FullName(String firstname, String lastname) {
_firstname = firstname;
_lastname = lastname;
}

@JsonCreator
public static FullName valueOf(String value) {
String[] mySplit = value.split("\\.");
return new FullName(mySplit[0], mySplit[1]);
}

public static FullName valueOf(String firstname, String lastname) {
return new FullName(firstname, lastname);
}

@JsonValue
@Override
public String toString() {
return _firstname + "." + _lastname;
}
}

public void testDeserializeKeyViaFactory() throws Exception
{
Map<FullName, Double> map =
new ObjectMapper().readValue("{\"first.last\": 42}",
new TypeReference<Map<FullName, Double>>() { });
Map.Entry<FullName, Double> entry = map.entrySet().iterator().next();
FullName key = entry.getKey();
assertEquals(key._firstname, "first");
assertEquals(key._lastname, "last");
assertEquals(entry.getValue().doubleValue(), 42, 0);
}
}

0 comments on commit 9257bd6

Please sign in to comment.