|
13 | 13 | import com.fasterxml.jackson.databind.cfg.ContextAttributes;
|
14 | 14 | import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
|
15 | 15 | import com.fasterxml.jackson.databind.introspect.Annotated;
|
| 16 | +import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition; |
16 | 17 | import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
17 | 18 | import com.fasterxml.jackson.databind.ser.*;
|
18 | 19 | import com.fasterxml.jackson.databind.ser.impl.FailingSerializer;
|
@@ -1145,6 +1146,41 @@ public void reportMappingProblem(Throwable t, String message, Object... args) th
|
1145 | 1146 | throw mappingException(t, message, args);
|
1146 | 1147 | }
|
1147 | 1148 |
|
| 1149 | + /** |
| 1150 | + * Helper method called to indicate problem in POJO (serialization) definitions or settings |
| 1151 | + * regarding specific Java type, unrelated to actual JSON content to map. |
| 1152 | + * Default behavior is to construct and throw a {@link JsonMappingException}. |
| 1153 | + * |
| 1154 | + * @since 2.9 |
| 1155 | + */ |
| 1156 | + public <T> T reportBadTypeDefinition(BeanDescription bean, |
| 1157 | + String message, Object... args) throws JsonMappingException { |
| 1158 | + if (args != null && args.length > 0) { |
| 1159 | + message = String.format(message, args); |
| 1160 | + } |
| 1161 | + String beanDesc = (bean == null) ? "N/A" : _desc(bean.getType().getGenericSignature()); |
| 1162 | + throw mappingException("Invalid type definition for type %s: %s", |
| 1163 | + beanDesc, message); |
| 1164 | + } |
| 1165 | + |
| 1166 | + /** |
| 1167 | + * Helper method called to indicate problem in POJO (serialization) definitions or settings |
| 1168 | + * regarding specific property (of a type), unrelated to actual JSON content to map. |
| 1169 | + * Default behavior is to construct and throw a {@link JsonMappingException}. |
| 1170 | + * |
| 1171 | + * @since 2.9 |
| 1172 | + */ |
| 1173 | + public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop, |
| 1174 | + String message, Object... args) throws JsonMappingException { |
| 1175 | + if (args != null && args.length > 0) { |
| 1176 | + message = String.format(message, args); |
| 1177 | + } |
| 1178 | + String propName = (prop == null) ? "N/A" : _desc(prop.getName()); |
| 1179 | + String beanDesc = (bean == null) ? "N/A" : _desc(bean.getType().getGenericSignature()); |
| 1180 | + throw mappingException("Invalid definition for property %s (of type %s): %s", |
| 1181 | + propName, beanDesc, message); |
| 1182 | + } |
| 1183 | + |
1148 | 1184 | /**
|
1149 | 1185 | * @since 2.8
|
1150 | 1186 | */
|
@@ -1304,6 +1340,13 @@ protected JsonSerializer<Object> _handleResolvable(JsonSerializer<?> ser)
|
1304 | 1340 | /**********************************************************
|
1305 | 1341 | */
|
1306 | 1342 |
|
| 1343 | + protected String _desc(Object value) { |
| 1344 | + if (value == null) { |
| 1345 | + return "N/A"; |
| 1346 | + } |
| 1347 | + return "'"+value+"'"; |
| 1348 | + } |
| 1349 | + |
1307 | 1350 | protected final DateFormat _dateFormat()
|
1308 | 1351 | {
|
1309 | 1352 | if (_dateFormat != null) {
|
|
0 commit comments