/
NewSchemaTest.java
54 lines (45 loc) · 1.72 KB
/
NewSchemaTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
}
}