Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a regression bug wrt serialization of enums (triggered a fail on …
…JSON-schema module)
- Loading branch information
1 parent
ee6a3ca
commit 6b2fbba
Showing
3 changed files
with
74 additions
and
8 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
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
54 changes: 54 additions & 0 deletions
54
src/test/java/com/fasterxml/jackson/databind/jsonschema/NewSchemaTest.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,54 @@ | ||
package com.fasterxml.jackson.databind.jsonschema; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; | ||
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor; | ||
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonValueFormat; | ||
|
||
/** | ||
* Basic tests to exercise low-level support added for JSON Schema module and | ||
* other modules that use type introspection. | ||
*/ | ||
public class NewSchemaTest extends BaseMapTest | ||
{ | ||
enum TestEnum { | ||
A, B, C; | ||
|
||
@Override | ||
public String toString() { | ||
return "ToString:"+name(); | ||
} | ||
} | ||
|
||
private final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
public void testSimpleEnum() throws Exception | ||
{ | ||
final Set<String> values = new TreeSet<String>(); | ||
ObjectWriter w = MAPPER.writer(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); | ||
|
||
w.acceptJsonFormatVisitor(TestEnum.class, new JsonFormatVisitorWrapper.Base() { | ||
@Override | ||
public JsonStringFormatVisitor expectStringFormat(JavaType type) { | ||
return new JsonStringFormatVisitor() { | ||
public void enumTypes(Set<String> enums) { | ||
values.addAll(enums); | ||
} | ||
|
||
@Override | ||
public void format(JsonValueFormat format) { } | ||
}; | ||
} | ||
}); | ||
|
||
assertEquals(3, values.size()); | ||
TreeSet<String> exp = new TreeSet<String>(Arrays.asList( | ||
"ToString:A", | ||
"ToString:B", | ||
"ToString:C" | ||
)); | ||
assertEquals(exp, values); | ||
} | ||
} |