6
6
import com .fasterxml .jackson .annotation .JsonFormat ;
7
7
import com .fasterxml .jackson .annotation .JsonInclude ;
8
8
9
+ import tools .jackson .databind .cfg .MapperConfig ;
9
10
import tools .jackson .databind .introspect .*;
10
11
import tools .jackson .databind .util .Annotations ;
11
12
@@ -280,21 +281,21 @@ public interface Supplier extends java.util.function.Supplier<BeanDescription>
280
281
JavaType getType ();
281
282
282
283
boolean isRecordType ();
284
+
285
+ JsonFormat .Value findExpectedFormat (MapperConfig <?> config , Class <?> baseType );
283
286
}
284
287
285
- /**
286
- * Partial implementation for lazily-constructed suppliers for {@link BeanDescription} instances.
287
- */
288
- public static abstract class LazySupplier implements Supplier
288
+ protected static abstract class SupplierBase implements Supplier
289
289
{
290
290
protected final JavaType _type ;
291
291
292
- protected transient AnnotatedClass _classDesc ;
292
+ /**
293
+ * Format definitions lazily introspected from class annotations
294
+ */
295
+ protected transient JsonFormat .Value _classFormat ;
293
296
294
- protected transient BeanDescription _beanDesc ;
295
-
296
- protected LazySupplier (JavaType type ) {
297
- _type = type ;
297
+ protected SupplierBase (JavaType type ) {
298
+ _type = type ;
298
299
}
299
300
300
301
// // Simple accessors:
@@ -308,6 +309,41 @@ protected LazySupplier(JavaType type) {
308
309
@ Override
309
310
public boolean isRecordType () { return _type .isRecordType (); }
310
311
312
+ // // // Introspection
313
+
314
+ @ Override
315
+ public JsonFormat .Value findExpectedFormat (MapperConfig <?> config , Class <?> baseType )
316
+ {
317
+ JsonFormat .Value v0 = _classFormat ;
318
+ if (v0 == null ) { // copied from above
319
+ v0 = config .getAnnotationIntrospector ().findFormat (config ,
320
+ getClassInfo ());
321
+ if (v0 == null ) {
322
+ v0 = JsonFormat .Value .empty ();
323
+ }
324
+ _classFormat = v0 ;
325
+ }
326
+ JsonFormat .Value v1 = config .getDefaultPropertyFormat (baseType );
327
+ if (v1 == null ) {
328
+ return v0 ;
329
+ }
330
+ return JsonFormat .Value .merge (v0 , v1 );
331
+ }
332
+ }
333
+
334
+ /**
335
+ * Partial implementation for lazily-constructed suppliers for {@link BeanDescription} instances.
336
+ */
337
+ public static abstract class LazySupplier extends SupplierBase
338
+ {
339
+ protected transient AnnotatedClass _classDesc ;
340
+
341
+ protected transient BeanDescription _beanDesc ;
342
+
343
+ protected LazySupplier (JavaType type ) {
344
+ super (type );
345
+ }
346
+
311
347
// // Entity accessors:
312
348
313
349
@ Override
@@ -334,6 +370,8 @@ public BeanDescription get() {
334
370
return _beanDesc ;
335
371
}
336
372
373
+ // // // Internal factory methods
374
+
337
375
protected abstract AnnotatedClass _introspect (JavaType forType );
338
376
339
377
protected abstract BeanDescription _construct (JavaType forType , AnnotatedClass ac );
@@ -343,23 +381,15 @@ public BeanDescription get() {
343
381
* Simple {@link Supplier} implementation that just returns pre-constructed
344
382
* {@link BeanDescription} instance.
345
383
*/
346
- public static class EagerSupplier implements Supplier
384
+ public static class EagerSupplier extends SupplierBase
347
385
{
348
386
protected final BeanDescription _beanDesc ;
349
387
350
388
public EagerSupplier (BeanDescription beanDesc ) {
351
- _beanDesc = Objects .requireNonNull (beanDesc );
389
+ super (beanDesc .getType ());
390
+ _beanDesc = beanDesc ;
352
391
}
353
392
354
- @ Override
355
- public Class <?> getBeanClass () { return _beanDesc .getBeanClass (); }
356
-
357
- @ Override
358
- public boolean isRecordType () { return getType ().isRecordType (); }
359
-
360
- @ Override
361
- public JavaType getType () { return _beanDesc .getType (); }
362
-
363
393
@ Override
364
394
public BeanDescription get () { return _beanDesc ; }
365
395
0 commit comments