Skip to content

Commit

Permalink
Merge pull request #924 from andreaTP/rem-reflection-apiclientbuilder
Browse files Browse the repository at this point in the history
Remove reflection from ApiClientBuilder
  • Loading branch information
baywet authored Dec 6, 2023
2 parents 926fca4 + 4ec7808 commit 8fe59ca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

## [0.11.0] - 2023-12-06

### Changed

- [breaking] Removed the usage of reflection in `ApiClientBuilder`

## [0.10.0] - 2023-11-22

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import jakarta.annotation.Nonnull;

import java.lang.reflect.InvocationTargetException;
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 {
Expand All @@ -19,40 +19,26 @@ private ApiClientBuilder() {}

/**
* Registers the default serializer to the registry.
* @param factoryClass the class of the factory to be registered.
* @param factorySupplier the supplier of the factory to be registered.
*/
public static void registerDefaultSerializer(
@Nonnull final Class<? extends SerializationWriterFactory> factoryClass) {
Objects.requireNonNull(factoryClass);
try {
final SerializationWriterFactory factory = factoryClass.getConstructor().newInstance();
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.put(
factory.getValidContentType(), factory);
} catch (InstantiationException
| IllegalAccessException
| NoSuchMethodException
| InvocationTargetException e) {
throw new RuntimeException(e);
}
@Nonnull final Supplier<SerializationWriterFactory> factorySupplier) {
Objects.requireNonNull(factorySupplier);
SerializationWriterFactory factory = factorySupplier.get();
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.put(
factory.getValidContentType(), factory);
}

/**
* Registers the default deserializer to the registry.
* @param factoryClass the class of the factory to be registered.
* @param factorySupplier the supplier of the factory to be registered.
*/
public static void registerDefaultDeserializer(
@Nonnull final Class<? extends ParseNodeFactory> factoryClass) {
Objects.requireNonNull(factoryClass);
try {
final ParseNodeFactory factory = factoryClass.getConstructor().newInstance();
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.put(
factory.getValidContentType(), factory);
} catch (InstantiationException
| IllegalAccessException
| NoSuchMethodException
| InvocationTargetException e) {
throw new RuntimeException(e);
}
@Nonnull final Supplier<ParseNodeFactory> factorySupplier) {
Objects.requireNonNull(factorySupplier);
ParseNodeFactory factory = factorySupplier.get();
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.put(
factory.getValidContentType(), factory);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ org.gradle.caching=true

mavenGroupId = com.microsoft.kiota
mavenMajorVersion = 0
mavenMinorVersion = 10
mavenMinorVersion = 11
mavenPatchVersion = 0
mavenArtifactSuffix =

Expand Down

0 comments on commit 8fe59ca

Please sign in to comment.