Skip to content

Commit 80155ba

Browse files
committed
More follow-up work wrt #4907
1 parent 649744e commit 80155ba

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

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

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.annotation.JsonFormat;
77
import com.fasterxml.jackson.annotation.JsonInclude;
88

9+
import tools.jackson.databind.cfg.MapperConfig;
910
import tools.jackson.databind.introspect.*;
1011
import tools.jackson.databind.util.Annotations;
1112

@@ -280,21 +281,21 @@ public interface Supplier extends java.util.function.Supplier<BeanDescription>
280281
JavaType getType();
281282

282283
boolean isRecordType();
284+
285+
JsonFormat.Value findExpectedFormat(MapperConfig<?> config, Class<?> baseType);
283286
}
284287

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
289289
{
290290
protected final JavaType _type;
291291

292-
protected transient AnnotatedClass _classDesc;
292+
/**
293+
* Format definitions lazily introspected from class annotations
294+
*/
295+
protected transient JsonFormat.Value _classFormat;
293296

294-
protected transient BeanDescription _beanDesc;
295-
296-
protected LazySupplier(JavaType type) {
297-
_type = type;
297+
protected SupplierBase(JavaType type) {
298+
_type = type;
298299
}
299300

300301
// // Simple accessors:
@@ -308,6 +309,41 @@ protected LazySupplier(JavaType type) {
308309
@Override
309310
public boolean isRecordType() { return _type.isRecordType(); }
310311

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+
311347
// // Entity accessors:
312348

313349
@Override
@@ -334,6 +370,8 @@ public BeanDescription get() {
334370
return _beanDesc;
335371
}
336372

373+
// // // Internal factory methods
374+
337375
protected abstract AnnotatedClass _introspect(JavaType forType);
338376

339377
protected abstract BeanDescription _construct(JavaType forType, AnnotatedClass ac);
@@ -343,23 +381,15 @@ public BeanDescription get() {
343381
* Simple {@link Supplier} implementation that just returns pre-constructed
344382
* {@link BeanDescription} instance.
345383
*/
346-
public static class EagerSupplier implements Supplier
384+
public static class EagerSupplier extends SupplierBase
347385
{
348386
protected final BeanDescription _beanDesc;
349387

350388
public EagerSupplier(BeanDescription beanDesc) {
351-
_beanDesc = Objects.requireNonNull(beanDesc);
389+
super(beanDesc.getType());
390+
_beanDesc = beanDesc;
352391
}
353392

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-
363393
@Override
364394
public BeanDescription get() { return _beanDesc; }
365395

src/main/java/tools/jackson/databind/deser/DeserializerCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ protected ValueDeserializer<?> _createDeserializer2(DeserializationContext ctxt,
378378
}
379379
if (type.isMapLikeType()) {
380380
// 11-Mar-2017, tatu: As per [databind#1554], also need to block
381-
// handling as Map if overriden with "as POJO" option.
381+
// handling as Map if overridden with "as POJO" option.
382382
// Ideally we'd determine it bit later on (to allow custom handler checks)
383383
// but that won't work for other reasons. So do it here.
384384
// (read: rewrite for 3.0)

0 commit comments

Comments
 (0)