Skip to content

Commit

Permalink
Refactoring after #4409 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 7, 2024
1 parent f1798b6 commit 2c0ed5e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,25 @@ public AnnotatedMember findAnySetterField() {
* defined by defaults and possible annotations.
* Note that this may be further refined by per-property annotations.
*
* @since 2.17
*/
public abstract JsonFormat.Value findExpectedFormat();

/**
* @since 2.1
* @deprecated Since 2.17 use {@link #findExpectedFormat()}
*/
public abstract JsonFormat.Value findExpectedFormat(JsonFormat.Value defValue);
@Deprecated // since 2.17
public JsonFormat.Value findExpectedFormat(JsonFormat.Value defValue) {
JsonFormat.Value v = findExpectedFormat();
if (defValue == null) {
return v;
}
if (v == null) {
return defValue;
}
return defValue.withOverrides(v);
}

/**
* Method for finding {@link Converter} used for serializing instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ protected BeanDeserializerBase(BeanDeserializerBuilder builder,
;

// Any transformation we may need to apply?
final JsonFormat.Value format = beanDesc.findExpectedFormat(null);
final JsonFormat.Value format = beanDesc.findExpectedFormat();
_serializationShape = format.getShape();

_needViewProcesing = hasViews;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ protected Map<String,List<PropertyName>> _collectAliases(Collection<SettableBean
protected boolean _findCaseInsensitivity() {
// 07-May-2020, tatu: First find combination of per-type config overrides (higher
// precedence) and per-type annotations (lower):
JsonFormat.Value format = _beanDesc.findExpectedFormat(null);
JsonFormat.Value format = _beanDesc.findExpectedFormat();
// and see if any of those has explicit definition; if not, use global baseline default
Boolean B = format.getFeature(JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
return (B == null) ? _config.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ protected JsonDeserializer<?> _createDeserializer2(DeserializationContext ctxt,
// Ideally we'd determine it bit later on (to allow custom handler checks)
// but that won't work for other reasons. So do it here.
// (read: rewrite for 3.0)
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
JsonFormat.Value format = beanDesc.findExpectedFormat();
if (format.getShape() != JsonFormat.Shape.OBJECT) {
MapLikeType mlt = (MapLikeType) type;
if (mlt instanceof MapType) {
Expand All @@ -421,7 +421,7 @@ protected JsonDeserializer<?> _createDeserializer2(DeserializationContext ctxt,
* (to allow custom handler checks), but that won't work for other
* reasons. So do it here.
*/
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
JsonFormat.Value format = beanDesc.findExpectedFormat();
if (format.getShape() != JsonFormat.Shape.OBJECT) {
CollectionLikeType clt = (CollectionLikeType) type;
if (clt instanceof CollectionType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,30 +405,25 @@ public AnnotatedMethod findMethod(String name, Class<?>[] paramTypes) {
/**********************************************************
*/

@Override
public JsonFormat.Value findExpectedFormat(JsonFormat.Value defValue)
@Override // since 2.17
public JsonFormat.Value findExpectedFormat()
{
JsonFormat.Value format = null;

// 15-Apr-2016, tatu: Let's check both per-type defaults and annotations; per-type
// defaults having higher precedence, so start with that
if (_annotationIntrospector != null) {
JsonFormat.Value v = _annotationIntrospector.findFormat(_classInfo);
if (v != null) {
if (defValue == null) {
defValue = v;
} else {
defValue = defValue.withOverrides(v);
}
}
format = _annotationIntrospector.findFormat(_classInfo);
}
JsonFormat.Value v = _config.getDefaultPropertyFormat(_classInfo.getRawType());
if (v != null) {
if (defValue == null) {
defValue = v;
if (format == null) {
format = v;
} else {
defValue = defValue.withOverrides(v);
format = format.withOverrides(v);
}
}
return defValue;
return format;
}

@Override // since 2.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ protected final JsonSerializer<?> findSerializerByPrimaryType(SerializerProvider
}
if (Number.class.isAssignableFrom(raw)) {
// 21-May-2014, tatu: Couple of alternatives actually
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
JsonFormat.Value format = beanDesc.findExpectedFormat();
switch (format.getShape()) {
case STRING:
return ToStringSerializer.instance;
Expand Down Expand Up @@ -713,7 +713,7 @@ protected JsonSerializer<?> buildCollectionSerializer(SerializerProvider prov,
if (ser == null) {
// We may also want to use serialize Collections "as beans", if (and only if)
// this is specified with `@JsonFormat(shape=Object)`
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
JsonFormat.Value format = beanDesc.findExpectedFormat();
if (format.getShape() == JsonFormat.Shape.OBJECT) {
return null;
}
Expand Down Expand Up @@ -803,7 +803,7 @@ protected JsonSerializer<?> buildMapSerializer(SerializerProvider prov,
{
// [databind#467]: This is where we could allow serialization "as POJO": But! It's
// nasty to undo, and does not apply on per-property basis. So, hardly optimal
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
JsonFormat.Value format = beanDesc.findExpectedFormat();
if (format.getShape() == JsonFormat.Shape.OBJECT) {
return null;
}
Expand Down Expand Up @@ -924,7 +924,7 @@ protected JsonSerializer<?> buildMapEntrySerializer(SerializerProvider prov,
// [databind#865]: Allow serialization "as POJO" -- note: to undo, declare
// serialization as `Shape.NATURAL` instead; that's JSON Object too.
JsonFormat.Value formatOverride = prov.getDefaultPropertyFormat(Map.Entry.class);
JsonFormat.Value formatFromAnnotation = beanDesc.findExpectedFormat(null);
JsonFormat.Value formatFromAnnotation = beanDesc.findExpectedFormat();
JsonFormat.Value format = JsonFormat.Value.merge(formatFromAnnotation, formatOverride);
if (format.getShape() == JsonFormat.Shape.OBJECT) {
return null;
Expand Down Expand Up @@ -1202,7 +1202,7 @@ protected JsonSerializer<?> buildEnumSerializer(SerializationConfig config,
* POJO style serialization, so we must handle that special case separately;
* otherwise pass it to EnumSerializer.
*/
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
JsonFormat.Value format = beanDesc.findExpectedFormat();
if (format.getShape() == JsonFormat.Shape.OBJECT) {
// one special case: suppress serialization of "getDeclaringClass()"...
((BasicBeanDescription) beanDesc).removeProperty("declaringClass");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected BeanSerializerBase(JavaType type, BeanSerializerBuilder builder,
_anyGetterWriter = builder.getAnyGetter();
_propertyFilterId = builder.getFilterId();
_objectIdWriter = builder.getObjectIdWriter();
final JsonFormat.Value format = builder.getBeanDescription().findExpectedFormat(null);
final JsonFormat.Value format = builder.getBeanDescription().findExpectedFormat();
_serializationShape = format.getShape();
}
}
Expand Down

0 comments on commit 2c0ed5e

Please sign in to comment.