Skip to content

Commit

Permalink
[eclipse-ee4j#617] Refactored repeated code in SerializationModelCrea…
Browse files Browse the repository at this point in the history
…tor & DeserializationModelCreator in serializer / deserializer creation from serializer / deserializer / adapter configuration in annotations

Signed-off-by: Anton Pinsky <[email protected]>
  • Loading branch information
api-from-the-ion committed Feb 12, 2024
1 parent e6054b2 commit fa1f4e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private ModelDeserializer<JsonParser> deserializerChainInternal(LinkedList<Type>
ModelDeserializer<JsonParser> deserializer = createUserOrAdapterDeserializer(type, (ComponentBoundCustomization) propertyCustomization,
(adapterToType) -> {
Class<?> toType = ReflectionUtils.getRawType(adapterToType);
return typeDeserializer(toType,
return typeDeserializer(toType,
jsonbContext.getMappingContext().getOrCreateClassModel(toType).getClassCustomization(),
JustReturn.instance());
},
Expand Down Expand Up @@ -365,9 +365,9 @@ private Set<String> collectIgnoredProperties(TypeInheritanceConfiguration typeIn
}

private Function<String, String> propertyRenamer() {
return jsonbContext.getConfig()
.getProperty(PROPERTY_NAMING_STRATEGY)
.filter(prop -> prop.equals(PropertyNamingStrategy.CASE_INSENSITIVE))
return jsonbContext.getConfig()
.getProperty(PROPERTY_NAMING_STRATEGY)
.filter(prop -> prop.equals(PropertyNamingStrategy.CASE_INSENSITIVE))
.map(val -> (Function<String, String>) String::toLowerCase).orElse(value -> value);
}

Expand All @@ -394,9 +394,9 @@ private ModelDeserializer<JsonParser> createUserOrAdapterDeserializer(Type type,
// try to create a deserializer from deserializer configuration
ComponentMatcher componentMatcher = jsonbContext.getComponentMatcher();
Optional<DeserializerBinding<?>> deserializerBinding = componentMatcher.getDeserializerBinding(type, customization);
return deserializerBinding.map(binding ->
(ModelDeserializer<JsonParser>) new UserDefinedDeserializer(binding.getComponent(), delegate, type, deserializerCustomization))
.orElseGet(() -> {
return deserializerBinding.map(binding ->
(ModelDeserializer<JsonParser>) new UserDefinedDeserializer(binding.getComponent(), delegate, type, deserializerCustomization))
.orElseGet(() -> {
// otherwise try to create a deserializer from adapter configuration or use alternative deserializer
Optional<AdapterBinding<?, ?>> adapterBinding = componentMatcher.getDeserializeAdapterBinding(type, customization);
return adapterBinding.map(adapter -> {
Expand All @@ -408,7 +408,7 @@ private ModelDeserializer<JsonParser> createUserOrAdapterDeserializer(Type type,
adapterDeserializer.deserialize(targetAdapterModel.deserialize(parser, adapterTypeDeserializerContextChangeFunction.apply(context)), context);
}).orElseGet(alternativeDeserializerSupplier);
});
}
}

private List<String> creatorParamsList(JsonbCreator creator) {
return Arrays.stream(creator.getParams()).map(CreatorModel::getName).collect(Collectors.toList());
Expand Down Expand Up @@ -457,7 +457,7 @@ private ModelDeserializer<JsonParser> typeProcessor(LinkedList<Type> chain,
if (deserializer != null) {
return deserializer;
}
return createNewChain(chain, memberDeserializer, resolveImplClass(rawType, customization), resolved, customization);
return createNewChain(chain, memberDeserializer, resolveImplClass(rawType, customization), resolved, customization);
}

private ModelDeserializer<JsonParser> createNewChain(LinkedList<Type> chain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,11 @@ private ModelSerializer createUserOrAdapterSerializer(Type type, Customization c
Function<ModelSerializer, ModelSerializer> wrapAdapterSerializerFunction) {

final ComponentMatcher componentMatcher = jsonbContext.getComponentMatcher();
return componentMatcher.getSerializerBinding(type, (ComponentBoundCustomization) customization)
.map(SerializerBinding::getComponent)
.map(UserDefinedSerializer::new)
.map(RecursionChecker::new)
.map(serializer -> SerializationModelCreator.wrapInCommonSet(serializer, customization, jsonbContext))
return componentMatcher.getSerializerBinding(type, (ComponentBoundCustomization) customization)
.map(SerializerBinding::getComponent)
.map(UserDefinedSerializer::new)
.map(RecursionChecker::new)
.map(serializer -> SerializationModelCreator.wrapInCommonSet(serializer, customization, jsonbContext))
.orElseGet(() -> {
Optional<AdapterBinding<?, ?>> adapterBinding = componentMatcher.getSerializeAdapterBinding(type, (ComponentBoundCustomization) customization);
return resolveRootAdapter ? adapterBinding.map(binding -> {
Expand All @@ -421,8 +421,8 @@ private ModelSerializer createUserOrAdapterSerializer(Type type, Customization c
AdapterSerializer adapterSerializer = new AdapterSerializer(binding, typeSerializer);
ModelSerializer wrappedAdapterSerializer = wrapAdapterSerializerFunction.apply(adapterSerializer);
return new NullSerializer(wrappedAdapterSerializer, customization, jsonbContext);
}).orElse(null) :
null;
}).orElse(null)
: null;
});
}

Expand Down

0 comments on commit fa1f4e1

Please sign in to comment.