|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.databind.JavaType;
|
4 | 4 | import com.fasterxml.jackson.databind.JsonMappingException;
|
| 5 | +import com.fasterxml.jackson.databind.SerializerProvider; |
5 | 6 |
|
6 | 7 | /**
|
7 | 8 | * Interface for visitor callbacks, when type in question can be any of
|
8 | 9 | * legal JSON types.
|
| 10 | + *<p> |
| 11 | + * In most cases it will make more sense to extend {@link JsonFormatVisitorWrapper.Base} |
| 12 | + * instead of directly implementing this interface. |
9 | 13 | */
|
10 | 14 | public interface JsonFormatVisitorWrapper extends JsonFormatVisitorWithSerializerProvider
|
11 | 15 | {
|
@@ -56,4 +60,86 @@ public interface JsonFormatVisitorWrapper extends JsonFormatVisitorWithSerialize
|
56 | 60 | * @since 2.2
|
57 | 61 | */
|
58 | 62 | public JsonMapFormatVisitor expectMapFormat(JavaType type) throws JsonMappingException;
|
| 63 | + |
| 64 | + /** |
| 65 | + * Empty "no-op" implementation of {@link JsonFormatVisitorWrapper}, suitable for |
| 66 | + * sub-classing. Does implement {@link #setProvider(SerializerProvider)} and |
| 67 | + * {@link #getProvider()} as expected; other methods simply return null |
| 68 | + * and do nothing. |
| 69 | + * |
| 70 | + * @since 2.5 |
| 71 | + */ |
| 72 | + public static class Base implements JsonFormatVisitorWrapper { |
| 73 | + protected SerializerProvider _provider; |
| 74 | + |
| 75 | + public Base() { } |
| 76 | + |
| 77 | + public Base(SerializerProvider p) { |
| 78 | + _provider = p; |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public SerializerProvider getProvider() { |
| 83 | + return _provider; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void setProvider(SerializerProvider p) { |
| 88 | + _provider = p; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public JsonObjectFormatVisitor expectObjectFormat(JavaType type) |
| 93 | + throws JsonMappingException { |
| 94 | + return null; |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public JsonArrayFormatVisitor expectArrayFormat(JavaType type) |
| 99 | + throws JsonMappingException { |
| 100 | + return null; |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public JsonStringFormatVisitor expectStringFormat(JavaType type) |
| 105 | + throws JsonMappingException { |
| 106 | + return null; |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public JsonNumberFormatVisitor expectNumberFormat(JavaType type) |
| 111 | + throws JsonMappingException { |
| 112 | + return null; |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public JsonIntegerFormatVisitor expectIntegerFormat(JavaType type) |
| 117 | + throws JsonMappingException { |
| 118 | + return null; |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public JsonBooleanFormatVisitor expectBooleanFormat(JavaType type) |
| 123 | + throws JsonMappingException { |
| 124 | + return null; |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public JsonNullFormatVisitor expectNullFormat(JavaType type) |
| 129 | + throws JsonMappingException { |
| 130 | + return null; |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public JsonAnyFormatVisitor expectAnyFormat(JavaType type) |
| 135 | + throws JsonMappingException { |
| 136 | + return null; |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public JsonMapFormatVisitor expectMapFormat(JavaType type) |
| 141 | + throws JsonMappingException { |
| 142 | + return null; |
| 143 | + } |
| 144 | + } |
59 | 145 | }
|
0 commit comments