From 4ec78089afcf7fe7a3121b8d853448f5e99d28c3 Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Wed, 6 Dec 2023 16:10:14 +0000 Subject: [PATCH] use supplier --- .../com/microsoft/kiota/ApiClientBuilder.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/abstractions/src/main/java/com/microsoft/kiota/ApiClientBuilder.java b/components/abstractions/src/main/java/com/microsoft/kiota/ApiClientBuilder.java index 3400a6856..b23b2b870 100644 --- a/components/abstractions/src/main/java/com/microsoft/kiota/ApiClientBuilder.java +++ b/components/abstractions/src/main/java/com/microsoft/kiota/ApiClientBuilder.java @@ -10,6 +10,7 @@ import jakarta.annotation.Nonnull; import java.util.Objects; +import java.util.function.Supplier; /** Provides a builder for creating an ApiClient and register the default serializers/deserializers. */ public class ApiClientBuilder { @@ -18,22 +19,24 @@ private ApiClientBuilder() {} /** * Registers the default serializer to the registry. - * @param factory the class of the factory to be registered. + * @param factorySupplier the supplier of the factory to be registered. */ public static void registerDefaultSerializer( - @Nonnull final SerializationWriterFactory factory) { - Objects.requireNonNull(factory); + @Nonnull final Supplier factorySupplier) { + Objects.requireNonNull(factorySupplier); + SerializationWriterFactory factory = factorySupplier.get(); SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.put( factory.getValidContentType(), factory); } /** * Registers the default deserializer to the registry. - * @param factory the class of the factory to be registered. + * @param factorySupplier the supplier of the factory to be registered. */ public static void registerDefaultDeserializer( - @Nonnull final ParseNodeFactory factory) { - Objects.requireNonNull(factory); + @Nonnull final Supplier factorySupplier) { + Objects.requireNonNull(factorySupplier); + ParseNodeFactory factory = factorySupplier.get(); ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.put( factory.getValidContentType(), factory); }