diff --git a/CHANGELOG.md b/CHANGELOG.md index 21b801634..4787e2512 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +## [0.10.0] - 2023-11-22 + ### Changed - Added Spotless as an automatic formatting tool for the entire codebase - Changed some internal implementations of JsonParse for performance and readability reasons +- [breaking] Removed the usage of reflection for enum deserialization and reordered `RequestAdapter` arguments order ## [0.9.2] - 2023-11-16 diff --git a/components/abstractions/src/main/java/com/microsoft/kiota/RequestAdapter.java b/components/abstractions/src/main/java/com/microsoft/kiota/RequestAdapter.java index 1bcd417b4..a7213eca1 100644 --- a/components/abstractions/src/main/java/com/microsoft/kiota/RequestAdapter.java +++ b/components/abstractions/src/main/java/com/microsoft/kiota/RequestAdapter.java @@ -3,6 +3,7 @@ import com.microsoft.kiota.serialization.Parsable; import com.microsoft.kiota.serialization.ParsableFactory; import com.microsoft.kiota.serialization.SerializationWriterFactory; +import com.microsoft.kiota.serialization.ValuedEnumParser; import com.microsoft.kiota.store.BackingStoreFactory; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; @@ -26,43 +27,41 @@ public interface RequestAdapter { /** * Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model. * @param requestInfo the request info to execute. - * @param factory the factory to create the parsable object from the type discriminator. * @param errorMappings the error factories mapping to use in case of a failed request. + * @param factory the factory to create the parsable object from the type discriminator. * @param the type of the response model to deserialize the response into. * @return the deserialized response model. */ - @SuppressWarnings("LambdaLast") @Nullable ModelType send( @Nonnull final RequestInformation requestInfo, - @Nonnull final ParsableFactory factory, - @Nullable final HashMap> errorMappings); + @Nullable final HashMap> errorMappings, + @Nonnull final ParsableFactory factory); /** * Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection. * @param requestInfo the request info to execute. - * @param factory the factory to create the parsable object from the type discriminator. * @param errorMappings the error factories mapping to use in case of a failed request. + * @param factory the factory to create the parsable object from the type discriminator. * @param the type of the response model to deserialize the response into. * @return the deserialized response model collection. */ - @SuppressWarnings("LambdaLast") @Nullable List sendCollection( @Nonnull final RequestInformation requestInfo, - @Nonnull final ParsableFactory factory, - @Nullable final HashMap> errorMappings); + @Nullable final HashMap> errorMappings, + @Nonnull final ParsableFactory factory); /** * Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model. * @param requestInfo the request info to execute. - * @param targetClass the class of the response model to deserialize the response into. * @param errorMappings the error factories mapping to use in case of a failed request. + * @param targetClass the class of the response model to deserialize the response into. * @param the type of the response model to deserialize the response into. * @return the deserialized primitive response model. */ @Nullable ModelType sendPrimitive( @Nonnull final RequestInformation requestInfo, - @Nonnull final Class targetClass, - @Nullable final HashMap> errorMappings); + @Nullable final HashMap> errorMappings, + @Nonnull final Class targetClass); /** * Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive collection response model. @@ -74,34 +73,34 @@ public interface RequestAdapter { */ @Nullable List sendPrimitiveCollection( @Nonnull final RequestInformation requestInfo, - @Nonnull final Class targetClass, - @Nullable final HashMap> errorMappings); + @Nullable final HashMap> errorMappings, + @Nonnull final Class targetClass); /** * Executes the HTTP request specified by the given RequestInformation and returns the deserialized enum value. * @param requestInfo the request info to execute. - * @param targetClass the class of the response model to deserialize the response into. * @param errorMappings the error factories mapping to use in case of a failed request. + * @param enumParser a parser from string to enum instances. * @param the type of the response model to deserialize the response into. * @return the deserialized primitive response model. */ @Nullable > ModelType sendEnum( @Nonnull final RequestInformation requestInfo, - @Nonnull final Class targetClass, - @Nullable final HashMap> errorMappings); + @Nullable final HashMap> errorMappings, + @Nonnull final ValuedEnumParser enumParser); /** * Executes the HTTP request specified by the given RequestInformation and returns the deserialized enum collection value. * @param requestInfo the request info to execute. - * @param targetClass the class of the response model to deserialize the response into. * @param errorMappings the error factories mapping to use in case of a failed request. + * @param enumParser a parser from string to enum instances. * @param the type of the response model to deserialize the response into. * @return the deserialized primitive response model. */ @Nullable > List sendEnumCollection( @Nonnull final RequestInformation requestInfo, - @Nonnull final Class targetClass, - @Nullable final HashMap> errorMappings); + @Nullable final HashMap> errorMappings, + @Nonnull final ValuedEnumParser enumParser); /** * Sets The base url for every request. diff --git a/components/abstractions/src/main/java/com/microsoft/kiota/serialization/ParseNode.java b/components/abstractions/src/main/java/com/microsoft/kiota/serialization/ParseNode.java index 9100e9c44..916a75762 100644 --- a/components/abstractions/src/main/java/com/microsoft/kiota/serialization/ParseNode.java +++ b/components/abstractions/src/main/java/com/microsoft/kiota/serialization/ParseNode.java @@ -110,18 +110,18 @@ public interface ParseNode { /** * Gets the Enum value of the node. * @return the Enum value of the node. - * @param targetEnum the class of the enum. + * @param enumParser the parser for Enums * @param the type of the enum. */ - @Nullable > T getEnumValue(@Nonnull final Class targetEnum); + @Nullable > T getEnumValue(@Nonnull final ValuedEnumParser enumParser); /** * Gets the EnumSet value of the node. * @return the EnumSet value of the node. - * @param targetEnum the class of the enum. + * @param enumParser the parser for Enums * @param the type of the enum. */ - @Nullable > EnumSet getEnumSetValue(@Nonnull final Class targetEnum); + @Nullable > EnumSet getEnumSetValue(@Nonnull final ValuedEnumParser enumParser); /** * Gets the collection of primitive values of the node. @@ -144,9 +144,10 @@ public interface ParseNode { * Gets the collection of Enum values of the node. * @return the collection of Enum values of the node. * @param the type of the enum. - * @param targetEnum the class of the enum + * @param enumParser the parser for Enums */ - @Nullable > List getCollectionOfEnumValues(@Nonnull final Class targetEnum); + @Nullable > List getCollectionOfEnumValues( + @Nonnull final ValuedEnumParser enumParser); /** * Gets the model object value of the node. diff --git a/components/abstractions/src/main/java/com/microsoft/kiota/serialization/ValuedEnumParser.java b/components/abstractions/src/main/java/com/microsoft/kiota/serialization/ValuedEnumParser.java new file mode 100644 index 000000000..35afdff04 --- /dev/null +++ b/components/abstractions/src/main/java/com/microsoft/kiota/serialization/ValuedEnumParser.java @@ -0,0 +1,15 @@ +package com.microsoft.kiota.serialization; + +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; + +/** The interface for a valued enum parser. */ +@FunctionalInterface +public interface ValuedEnumParser { + /** + * Gets an enum from it's string value. + * @param value the string value of the enum. + * @return the enum value derived from the string. + */ + @Nullable T forValue(@Nonnull String value); +} diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java index bd77974d5..4d9dbabb1 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java @@ -10,6 +10,7 @@ import com.microsoft.kiota.serialization.ParseNodeFactoryRegistry; import com.microsoft.kiota.serialization.SerializationWriterFactory; import com.microsoft.kiota.serialization.SerializationWriterFactoryRegistry; +import com.microsoft.kiota.serialization.ValuedEnumParser; import com.microsoft.kiota.store.BackingStoreFactory; import com.microsoft.kiota.store.BackingStoreFactorySingleton; import io.opentelemetry.api.GlobalOpenTelemetry; @@ -172,13 +173,13 @@ public void enableBackingStore(@Nullable final BackingStoreFactory backingStoreF } private static final String nullRequestInfoParameter = "parameter requestInfo cannot be null"; - private static final String nullTargetClassParameter = "parameter targetClass cannot be null"; + private static final String nullEnumParserParameter = "parameter enumParser cannot be null"; private static final String nullFactoryParameter = "parameter factory cannot be null"; @Nullable public List sendCollection( @Nonnull final RequestInformation requestInfo, - @Nonnull final ParsableFactory factory, - @Nullable final HashMap> errorMappings) { + @Nullable final HashMap> errorMappings, + @Nonnull final ParsableFactory factory) { Objects.requireNonNull(requestInfo, nullRequestInfoParameter); Objects.requireNonNull(factory, nullFactoryParameter); @@ -258,8 +259,8 @@ private Span startSpan( @Nullable public ModelType send( @Nonnull final RequestInformation requestInfo, - @Nonnull final ParsableFactory factory, - @Nullable final HashMap> errorMappings) { + @Nullable final HashMap> errorMappings, + @Nonnull final ParsableFactory factory) { Objects.requireNonNull(requestInfo, nullRequestInfoParameter); Objects.requireNonNull(factory, nullFactoryParameter); @@ -321,10 +322,10 @@ private void closeResponse(boolean closeResponse, Response response) { @Nullable public ModelType sendPrimitive( @Nonnull final RequestInformation requestInfo, - @Nonnull final Class targetClass, - @Nullable final HashMap> errorMappings) { + @Nullable final HashMap> errorMappings, + @Nonnull final Class targetClass) { Objects.requireNonNull(requestInfo, nullRequestInfoParameter); - Objects.requireNonNull(targetClass, nullTargetClassParameter); + Objects.requireNonNull(targetClass, "parameter targetClass cannot be null"); final Span span = startSpan(requestInfo, "sendPrimitiveAsync"); try (final Scope scope = span.makeCurrent()) { Response response = this.getHttpResponseMessage(requestInfo, span, span, null); @@ -415,10 +416,10 @@ private void closeResponse(boolean closeResponse, Response response) { @Nullable public > ModelType sendEnum( @Nonnull final RequestInformation requestInfo, - @Nonnull final Class targetClass, - @Nullable final HashMap> errorMappings) { + @Nullable final HashMap> errorMappings, + @Nonnull final ValuedEnumParser enumParser) { Objects.requireNonNull(requestInfo, nullRequestInfoParameter); - Objects.requireNonNull(targetClass, nullTargetClassParameter); + Objects.requireNonNull(enumParser, nullEnumParserParameter); final Span span = startSpan(requestInfo, "sendEnumAsync"); try (final Scope scope = span.makeCurrent()) { Response response = this.getHttpResponseMessage(requestInfo, span, span, null); @@ -441,7 +442,7 @@ private void closeResponse(boolean closeResponse, Response response) { .setParent(Context.current().with(span)) .startSpan(); try (final Scope deserializationScope = deserializationSpan.makeCurrent()) { - final Object result = rootNode.getEnumValue(targetClass); + final Object result = rootNode.getEnumValue(enumParser::forValue); setResponseType(result, span); return (ModelType) result; } finally { @@ -461,10 +462,10 @@ private void closeResponse(boolean closeResponse, Response response) { @Nullable public > List sendEnumCollection( @Nonnull final RequestInformation requestInfo, - @Nonnull final Class targetClass, - @Nullable final HashMap> errorMappings) { + @Nullable final HashMap> errorMappings, + @Nonnull final ValuedEnumParser enumParser) { Objects.requireNonNull(requestInfo, nullRequestInfoParameter); - Objects.requireNonNull(targetClass, nullTargetClassParameter); + Objects.requireNonNull(enumParser, nullEnumParserParameter); final Span span = startSpan(requestInfo, "sendEnumCollectionAsync"); try (final Scope scope = span.makeCurrent()) { Response response = this.getHttpResponseMessage(requestInfo, span, span, null); @@ -487,7 +488,8 @@ private void closeResponse(boolean closeResponse, Response response) { .setParent(Context.current().with(span)) .startSpan(); try (final Scope deserializationScope = deserializationSpan.makeCurrent()) { - final Object result = rootNode.getCollectionOfEnumValues(targetClass); + final Object result = + rootNode.getCollectionOfEnumValues(enumParser::forValue); setResponseType(result, span); return (List) result; } finally { @@ -507,8 +509,8 @@ private void closeResponse(boolean closeResponse, Response response) { @Nullable public List sendPrimitiveCollection( @Nonnull final RequestInformation requestInfo, - @Nonnull final Class targetClass, - @Nullable final HashMap> errorMappings) { + @Nullable final HashMap> errorMappings, + @Nonnull final Class targetClass) { Objects.requireNonNull(requestInfo, nullRequestInfoParameter); final Span span = startSpan(requestInfo, "sendPrimitiveCollectionAsync"); diff --git a/components/http/okHttp/src/test/java/com/microsoft/kiota/http/OkHttpRequestAdapterTest.java b/components/http/okHttp/src/test/java/com/microsoft/kiota/http/OkHttpRequestAdapterTest.java index b18aa87e8..53257d781 100644 --- a/components/http/okHttp/src/test/java/com/microsoft/kiota/http/OkHttpRequestAdapterTest.java +++ b/components/http/okHttp/src/test/java/com/microsoft/kiota/http/OkHttpRequestAdapterTest.java @@ -96,7 +96,7 @@ void SendStreamReturnsUsableStream(int statusCode) throws Exception { }; InputStream response = null; try { - response = requestAdapter.sendPrimitive(requestInformation, InputStream.class, null); + response = requestAdapter.sendPrimitive(requestInformation, null, InputStream.class); assertNotNull(response); assertEquals(text, new String(response.readAllBytes(), StandardCharsets.UTF_8)); } finally { @@ -131,7 +131,7 @@ public void SendStreamReturnsNullOnNoContent(int statusCode) throws Exception { } }; final var response = - requestAdapter.sendPrimitive(requestInformation, InputStream.class, null); + requestAdapter.sendPrimitive(requestInformation, null, InputStream.class); assertNull(response); } @@ -161,7 +161,7 @@ public void SendReturnsNullOnNoContent(int statusCode) throws Exception { }; final var mockEntity = mock(Parsable.class); when(mockEntity.getFieldDeserializers()).thenReturn(new HashMap<>()); - final var response = requestAdapter.send(requestInformation, (node) -> mockEntity, null); + final var response = requestAdapter.send(requestInformation, null, (node) -> mockEntity); assertNull(response); } @@ -200,7 +200,7 @@ public void SendReturnsObjectOnContent(int statusCode) throws Exception { when(mockFactory.getValidContentType()).thenReturn("application/json"); final var requestAdapter = new OkHttpRequestAdapter(authenticationProviderMock, mockFactory, null, client); - final var response = requestAdapter.send(requestInformation, (node) -> mockEntity, null); + final var response = requestAdapter.send(requestInformation, null, (node) -> mockEntity); assertNotNull(response); } @@ -242,7 +242,7 @@ public void throwsAPIException() throws Exception { final var exception = assertThrows( ApiException.class, - () -> requestAdapter.send(requestInformation, (node) -> mockEntity, null)); + () -> requestAdapter.send(requestInformation, null, (node) -> mockEntity)); assertNotNull(exception); assertEquals(404, exception.getResponseStatusCode()); assertTrue(exception.getResponseHeaders().containsKey("request-id")); diff --git a/components/serialization/form/src/main/java/com/microsoft/kiota/serialization/FormParseNode.java b/components/serialization/form/src/main/java/com/microsoft/kiota/serialization/FormParseNode.java index 3f895cca1..e1a568c8d 100644 --- a/components/serialization/form/src/main/java/com/microsoft/kiota/serialization/FormParseNode.java +++ b/components/serialization/form/src/main/java/com/microsoft/kiota/serialization/FormParseNode.java @@ -4,7 +4,6 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import java.io.UnsupportedEncodingException; -import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; @@ -260,8 +259,8 @@ public T next() { } @Nullable public > List getCollectionOfEnumValues( - @Nonnull final Class targetEnum) { - Objects.requireNonNull(targetEnum, "parameter targetEnum cannot be null"); + @Nonnull final ValuedEnumParser enumParser) { + Objects.requireNonNull(enumParser, "parameter enumParser cannot be null"); final String stringValue = getStringValue(); if (stringValue == null || stringValue.isEmpty()) { return null; @@ -269,7 +268,7 @@ public T next() { final String[] array = stringValue.split(","); final ArrayList result = new ArrayList<>(); for (final String item : array) { - result.add(getEnumValueInt(item, targetEnum)); + result.add(enumParser.forValue(item)); } return result; } @@ -282,41 +281,29 @@ public T next() { return item; } - @Nullable public > T getEnumValue(@Nonnull final Class targetEnum) { + @Nullable public > T getEnumValue(@Nonnull final ValuedEnumParser enumParser) { final String rawValue = this.getStringValue(); if (rawValue == null || rawValue.isEmpty()) { return null; } - return getEnumValueInt(rawValue, targetEnum); + return enumParser.forValue(rawValue); } - @SuppressWarnings("unchecked") - private > T getEnumValueInt( - @Nonnull final String rawValue, @Nonnull final Class targetEnum) { - try { - return (T) targetEnum.getMethod("forValue", String.class).invoke(null, rawValue); - } catch (SecurityException - | IllegalAccessException - | InvocationTargetException - | NoSuchMethodException ex) { - return null; - } - } - - @Nullable public > EnumSet getEnumSetValue(@Nonnull final Class targetEnum) { + @Nullable public > EnumSet getEnumSetValue( + @Nonnull final ValuedEnumParser enumParser) { final String rawValue = this.getStringValue(); if (rawValue == null || rawValue.isEmpty()) { return null; } - final EnumSet result = EnumSet.noneOf(targetEnum); + final List result = new ArrayList<>(); final String[] rawValues = rawValue.split(","); for (final String rawValueItem : rawValues) { - final T value = getEnumValueInt(rawValueItem, targetEnum); + final T value = enumParser.forValue(rawValueItem); if (value != null) { result.add(value); } } - return result; + return EnumSet.copyOf(result); } private void assignFieldValues( diff --git a/components/serialization/json/src/main/java/com/microsoft/kiota/serialization/JsonParseNode.java b/components/serialization/json/src/main/java/com/microsoft/kiota/serialization/JsonParseNode.java index bc0832bda..dbfdd75d5 100644 --- a/components/serialization/json/src/main/java/com/microsoft/kiota/serialization/JsonParseNode.java +++ b/components/serialization/json/src/main/java/com/microsoft/kiota/serialization/JsonParseNode.java @@ -7,7 +7,6 @@ import com.microsoft.kiota.PeriodAndDuration; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; -import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalTime; @@ -184,12 +183,12 @@ private List iterateOnArray(Function fn) { } @Nullable public > List getCollectionOfEnumValues( - @Nonnull final Class targetEnum) { - Objects.requireNonNull(targetEnum, "parameter targetEnum cannot be null"); + @Nonnull final ValuedEnumParser enumParser) { + Objects.requireNonNull(enumParser, "parameter enumParser cannot be null"); if (currentNode.isJsonNull()) { return null; } else if (currentNode.isJsonArray()) { - return iterateOnArray(itemNode -> itemNode.getEnumValue(targetEnum)); + return iterateOnArray(itemNode -> itemNode.getEnumValue(enumParser)); } else throw new RuntimeException("invalid state expected to have an array node"); } @@ -200,41 +199,29 @@ private List iterateOnArray(Function fn) { return item; } - @Nullable public > T getEnumValue(@Nonnull final Class targetEnum) { + @Nullable public > T getEnumValue(@Nonnull final ValuedEnumParser enumParser) { final String rawValue = this.getStringValue(); if (rawValue == null || rawValue.isEmpty()) { return null; } - return getEnumValueInt(rawValue, targetEnum); + return enumParser.forValue(rawValue); } - @SuppressWarnings("unchecked") - private > T getEnumValueInt( - @Nonnull final String rawValue, @Nonnull final Class targetEnum) { - try { - return (T) targetEnum.getMethod("forValue", String.class).invoke(null, rawValue); - } catch (NoSuchMethodException - | IllegalAccessException - | InvocationTargetException - | SecurityException ex) { - return null; - } - } - - @Nullable public > EnumSet getEnumSetValue(@Nonnull final Class targetEnum) { + @Nullable public > EnumSet getEnumSetValue( + @Nonnull final ValuedEnumParser enumParser) { final String rawValue = this.getStringValue(); if (rawValue == null || rawValue.isEmpty()) { return null; } - final EnumSet result = EnumSet.noneOf(targetEnum); + final List result = new ArrayList<>(); final String[] rawValues = rawValue.split(","); for (final String rawValueItem : rawValues) { - final T value = getEnumValueInt(rawValueItem, targetEnum); + final T value = enumParser.forValue(rawValueItem); if (value != null) { result.add(value); } } - return result; + return EnumSet.copyOf(result); } private void assignFieldValues( diff --git a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/MyEnum.java b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/MyEnum.java index 65067051f..e91ac7175 100644 --- a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/MyEnum.java +++ b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/MyEnum.java @@ -1,6 +1,8 @@ package com.microsoft.kiota.serialization.mocks; import com.microsoft.kiota.serialization.ValuedEnum; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; import java.util.Objects; public enum MyEnum implements ValuedEnum { @@ -12,11 +14,11 @@ public enum MyEnum implements ValuedEnum { this.value = value; } - @jakarta.annotation.Nonnull public String getValue() { + @Nonnull public String getValue() { return this.value; } - @jakarta.annotation.Nullable public static MyEnum forValue(@jakarta.annotation.Nonnull final String searchValue) { + @Nullable public static MyEnum forValue(@jakarta.annotation.Nonnull final String searchValue) { Objects.requireNonNull(searchValue); switch (searchValue) { case "VALUE1": diff --git a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/TestEntity.java b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/TestEntity.java index d5ec68c6b..786b7db3e 100644 --- a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/TestEntity.java +++ b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/TestEntity.java @@ -131,7 +131,7 @@ public Map> getFieldDeserializers() { put( "myEnum", (n) -> { - setMyEnum(n.getEnumValue(MyEnum.class)); + setMyEnum(n.getEnumValue(MyEnum::forValue)); }); put( "createdDateTime", diff --git a/components/serialization/text/src/main/java/com/microsoft/kiota/serialization/TextParseNode.java b/components/serialization/text/src/main/java/com/microsoft/kiota/serialization/TextParseNode.java index 3028234b7..bae1911c6 100644 --- a/components/serialization/text/src/main/java/com/microsoft/kiota/serialization/TextParseNode.java +++ b/components/serialization/text/src/main/java/com/microsoft/kiota/serialization/TextParseNode.java @@ -3,7 +3,6 @@ import com.microsoft.kiota.PeriodAndDuration; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; -import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalTime; @@ -103,7 +102,7 @@ public TextParseNode(@Nonnull final String rawText) { } @Nullable public > List getCollectionOfEnumValues( - @Nonnull final Class targetEnum) { + @Nonnull final ValuedEnumParser enumParser) { throw new UnsupportedOperationException(NO_STRUCTURED_DATA_MESSAGE); } @@ -111,28 +110,16 @@ public TextParseNode(@Nonnull final String rawText) { throw new UnsupportedOperationException(NO_STRUCTURED_DATA_MESSAGE); } - @Nullable public > T getEnumValue(@Nonnull final Class targetEnum) { + @Nullable public > T getEnumValue(@Nonnull final ValuedEnumParser enumParser) { final String rawValue = this.getStringValue(); if (rawValue == null || rawValue.isEmpty()) { return null; } - return getEnumValueInt(rawValue, targetEnum); - } - - @SuppressWarnings("unchecked") - private > T getEnumValueInt( - @Nonnull final String rawValue, @Nonnull final Class targetEnum) { - try { - return (T) targetEnum.getMethod("forValue", String.class).invoke(null, rawValue); - } catch (SecurityException - | IllegalAccessException - | InvocationTargetException - | NoSuchMethodException ex) { - return null; - } + return enumParser.forValue(rawValue); } - @Nullable public > EnumSet getEnumSetValue(@Nonnull final Class targetEnum) { + @Nullable public > EnumSet getEnumSetValue( + @Nonnull final ValuedEnumParser enumParser) { throw new UnsupportedOperationException(NO_STRUCTURED_DATA_MESSAGE); } diff --git a/gradle.properties b/gradle.properties index 73f091d4e..7524b49e2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,8 +25,8 @@ org.gradle.caching=true mavenGroupId = com.microsoft.kiota mavenMajorVersion = 0 -mavenMinorVersion = 9 -mavenPatchVersion = 2 +mavenMinorVersion = 10 +mavenPatchVersion = 0 mavenArtifactSuffix = #These values are used to run functional tests