Skip to content

Commit 4cd512d

Browse files
committed
Bit of refactoring for BeanDescription.Supplier (post #5093, #5094)
1 parent a0948db commit 4cd512d

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

src/main/java/tools/jackson/databind/BeanDescription.java

+46-12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ protected BeanDescription(JavaType type) {
3636
_type = type;
3737
}
3838

39+
public BeanDescription.Supplier supplier() {
40+
return new EagerSupplier(this);
41+
}
42+
3943
/*
4044
/**********************************************************************
4145
/* Simple accessors
@@ -303,30 +307,45 @@ public AnnotatedMember findJsonKeyAccessor() {
303307
/**
304308
* Base implementation for lazily-constructed suppliers for {@link BeanDescription} instances.
305309
*/
306-
public static abstract class Supplier implements java.util.function.Supplier<BeanDescription>
310+
public interface Supplier extends java.util.function.Supplier<BeanDescription>
311+
{
312+
JavaType getType();
313+
314+
default Class<?> getBeanClass() { return getType().getRawClass(); }
315+
316+
default boolean isRecordType() { return getType().isRecordType(); }
317+
318+
default AnnotatedClass getClassInfo() {
319+
return get().getClassInfo();
320+
}
321+
322+
default Annotations getClassAnnotations() {
323+
return get().getClassAnnotations();
324+
}
325+
326+
@Override
327+
public BeanDescription get();
328+
}
329+
330+
public static abstract class LazySupplier implements Supplier
307331
{
308-
private final JavaType _type;
332+
protected final JavaType _type;
309333

310-
private transient BeanDescription _beanDesc;
334+
protected transient BeanDescription _beanDesc;
311335

312-
protected Supplier(JavaType type) {
336+
protected LazySupplier(JavaType type) {
313337
_type = type;
314338
}
315339

340+
@Override
316341
public JavaType getType() { return _type; }
317342

343+
@Override
318344
public Class<?> getBeanClass() { return _type.getRawClass(); }
319345

346+
@Override
320347
public boolean isRecordType() { return _type.isRecordType(); }
321348

322-
public AnnotatedClass getClassInfo() {
323-
return get().getClassInfo();
324-
}
325-
326-
public Annotations getClassAnnotations() {
327-
return get().getClassAnnotations();
328-
}
329-
330349
@Override
331350
public BeanDescription get() {
332351
if (_beanDesc == null) {
@@ -337,4 +356,19 @@ public BeanDescription get() {
337356

338357
protected abstract BeanDescription _construct(JavaType forType);
339358
}
359+
360+
public static class EagerSupplier implements Supplier
361+
{
362+
protected final BeanDescription _beanDesc;
363+
364+
public EagerSupplier(BeanDescription beanDesc) {
365+
_beanDesc = Objects.requireNonNull(beanDesc);
366+
}
367+
368+
@Override
369+
public JavaType getType() { return _beanDesc.getType(); }
370+
371+
@Override
372+
public BeanDescription get() { return _beanDesc; }
373+
}
340374
}

src/main/java/tools/jackson/databind/DatabindContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ protected abstract DatabindException invalidTypeIdException(JavaType baseType, S
313313
public abstract BeanDescription introspectBeanDescription(JavaType type);
314314

315315
public BeanDescription.Supplier lazyIntrospectBeanDescription(JavaType type) {
316-
return new BeanDescription.Supplier(type) {
316+
return new BeanDescription.LazySupplier(type) {
317317
@Override
318318
public BeanDescription _construct(JavaType forType) {
319319
return introspectBeanDescription(forType);

src/main/java/tools/jackson/databind/DeserializationContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ public BeanDescription introspectBeanDescriptionForCreation(JavaType type) {
537537
}
538538

539539
public BeanDescription.Supplier lazyIntrospectBeanDescriptionForCreation(JavaType type) {
540-
return new BeanDescription.Supplier(type) {
540+
return new BeanDescription.LazySupplier(type) {
541541
@Override
542542
public BeanDescription _construct(JavaType forType) {
543543
return introspectBeanDescriptionForCreation(forType);
@@ -553,7 +553,7 @@ public BeanDescription introspectBeanDescriptionForBuilder(JavaType builderType,
553553

554554
public BeanDescription.Supplier lazyIntrospectBeanDescriptionForBuilder(final JavaType builderType,
555555
final BeanDescription valueTypeDesc) {
556-
return new BeanDescription.Supplier(builderType) {
556+
return new BeanDescription.LazySupplier(builderType) {
557557
@Override
558558
public BeanDescription _construct(JavaType forType) {
559559
return introspectBeanDescriptionForBuilder(forType, valueTypeDesc);

0 commit comments

Comments
 (0)