-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
5b78983
commit 7e35baa
Showing
2 changed files
with
43 additions
and
0 deletions.
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
40 changes: 40 additions & 0 deletions
40
src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EnumDeser682Test.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,40 @@ | ||
package com.fasterxml.jackson.dataformat.xml.deser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
|
||
public class EnumDeser682Test extends XmlTestBase | ||
{ | ||
static enum Country { | ||
ITALY("Italy"), | ||
NETHERLANDS("Netherlands"); | ||
|
||
@JsonValue | ||
final String value; | ||
|
||
Country(String value) { | ||
this.value = value; | ||
} | ||
|
||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING) | ||
public static Country fromValue(String value) { | ||
for (Country b : Country.values()) { | ||
if (b.value.equals(value)) { | ||
return b; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unexpected value '" + value + "'"); | ||
} | ||
} | ||
|
||
private final ObjectMapper MAPPER = newMapper(); | ||
|
||
public void testEnumDeser682() throws Exception { | ||
String xml = MAPPER.writeValueAsString(Country.ITALY); | ||
assertEquals("<Country>Italy</Country>", xml); | ||
|
||
assertEquals(Country.ITALY, MAPPER.readValue(xml, Country.class)); | ||
} | ||
} |