-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9904fa
commit 9257bd6
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/test/java/com/fasterxml/jackson/failing/KeyDeser1429Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |