From 7ae362777dfe6927f4e99c5421bea89565573773 Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Wed, 3 Jan 2024 11:39:56 +0000 Subject: [PATCH 1/2] changelog --- CHANGELOG.md | 4 + .../serialization/KiotaSerialization.java | 83 ------------------- 2 files changed, 4 insertions(+), 83 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f08848bc..c35cdf4a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +### Changed + +- Removed methods using reflection from `KiotaSerialization` + ## [0.12.1] - 2024-01-10 ### Changed diff --git a/components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaSerialization.java b/components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaSerialization.java index ea4f257da..e7b06eb13 100644 --- a/components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaSerialization.java +++ b/components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaSerialization.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; import java.util.List; import java.util.Objects; @@ -183,86 +182,4 @@ private static InputStream getInputStreamFromString(@Nonnull final String value) final ParseNode parseNode = getRootParseNode(contentType, stream, parsableFactory); return parseNode.getCollectionOfObjectValues(parsableFactory); } - - /** - * Deserializes the given stream to a model object - * @param the type of the value to deserialize - * @param contentType the content type to use for deserialization - * @param stream the stream to deserialize - * @param typeClass the class of the model object - * @return the deserialized value - */ - @Nonnull public static T deserialize( - @Nonnull final String contentType, - @Nonnull final InputStream stream, - @Nonnull final Class typeClass) { - return deserialize(contentType, stream, getFactoryMethodFromType(typeClass)); - } - - /** - * Deserializes the given string to a model object - * @param the type of the value to deserialize - * @param contentType the content type to use for deserialization - * @param value the string to deserialize - * @param typeClass the class of the model object - * @return the deserialized value - * @throws IOException when the stream cannot be closed or read. - */ - @Nonnull public static T deserialize( - @Nonnull final String contentType, - @Nonnull final String value, - @Nonnull final Class typeClass) - throws IOException { - return deserialize(contentType, value, getFactoryMethodFromType(typeClass)); - } - - /** - * Deserializes the given stream to a collection of model objects - * @param the type of the value to deserialize - * @param contentType the content type to use for deserialization - * @param stream the stream to deserialize - * @param typeClass the class of the model object - * @return the deserialized value - */ - @Nonnull public static List deserializeCollection( - @Nonnull final String contentType, - @Nonnull final InputStream stream, - @Nonnull final Class typeClass) { - return deserializeCollection(contentType, stream, getFactoryMethodFromType(typeClass)); - } - - /** - * Deserializes the given string to a collection of model objects - * @param the type of the value to deserialize - * @param contentType the content type to use for deserialization - * @param value the string to deserialize - * @param typeClass the class of the model object - * @return the deserialized value - * @throws IOException when the stream cannot be closed or read. - */ - @Nonnull public static List deserializeCollection( - @Nonnull final String contentType, - @Nonnull final String value, - @Nonnull final Class typeClass) - throws IOException { - return deserializeCollection(contentType, value, getFactoryMethodFromType(typeClass)); - } - - @SuppressWarnings("unchecked") - @Nonnull private static ParsableFactory getFactoryMethodFromType( - @Nonnull final Class type) { - Objects.requireNonNull(type); - try { - final Method method = type.getMethod("createFromDiscriminatorValue", ParseNode.class); - return node -> { - try { - return (T) method.invoke(null, node); - } catch (final Exception e) { - throw new RuntimeException(e); - } - }; - } catch (final Exception e) { - throw new RuntimeException(e); - } - } } From 87dda24d5503bdb506d3ddcf0ec2152827f0d021 Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Wed, 3 Jan 2024 11:46:32 +0000 Subject: [PATCH 2/2] more fixes and fmt --- .../serialization/KiotaJsonSerialization.java | 50 ------------------- .../DeserializationHelpersTest.java | 3 +- 2 files changed, 2 insertions(+), 51 deletions(-) diff --git a/components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaJsonSerialization.java b/components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaJsonSerialization.java index 70ea3bb38..046c81019 100644 --- a/components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaJsonSerialization.java +++ b/components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaJsonSerialization.java @@ -113,54 +113,4 @@ private KiotaJsonSerialization() {} @Nonnull final InputStream stream, @Nonnull final ParsableFactory parsableFactory) { return KiotaSerialization.deserializeCollection(CONTENT_TYPE, stream, parsableFactory); } - - /** - * Deserializes the given stream to a model object - * @param the type of the value to deserialize - * @param stream the stream to deserialize - * @param typeClass the class of the model object - * @return the deserialized value - */ - @Nonnull public static T deserialize( - @Nonnull final InputStream stream, @Nonnull final Class typeClass) { - return KiotaSerialization.deserialize(CONTENT_TYPE, stream, typeClass); - } - - /** - * Deserializes the given string to a model object - * @param the type of the value to deserialize - * @param value the string to deserialize - * @param typeClass the class of the model object - * @return the deserialized value - * @throws IOException when the stream cannot be closed or read. - */ - @Nonnull public static T deserialize( - @Nonnull final String value, @Nonnull final Class typeClass) throws IOException { - return KiotaSerialization.deserialize(CONTENT_TYPE, value, typeClass); - } - - /** - * Deserializes the given stream to a collection of model objects - * @param the type of the value to deserialize - * @param stream the stream to deserialize - * @param typeClass the class of the model object - * @return the deserialized value - */ - @Nonnull public static List deserializeCollection( - @Nonnull final InputStream stream, @Nonnull final Class typeClass) { - return KiotaSerialization.deserializeCollection(CONTENT_TYPE, stream, typeClass); - } - - /** - * Deserializes the given string to a collection of model objects - * @param the type of the value to deserialize - * @param value the string to deserialize - * @param typeClass the class of the model object - * @return the deserialized value - * @throws IOException when the stream cannot be closed or read. - */ - @Nonnull public static List deserializeCollection( - @Nonnull final String value, @Nonnull final Class typeClass) throws IOException { - return KiotaSerialization.deserializeCollection(CONTENT_TYPE, value, typeClass); - } } diff --git a/components/abstractions/src/test/java/com/microsoft/kiota/serialization/DeserializationHelpersTest.java b/components/abstractions/src/test/java/com/microsoft/kiota/serialization/DeserializationHelpersTest.java index e71534679..ae379e77d 100644 --- a/components/abstractions/src/test/java/com/microsoft/kiota/serialization/DeserializationHelpersTest.java +++ b/components/abstractions/src/test/java/com/microsoft/kiota/serialization/DeserializationHelpersTest.java @@ -108,7 +108,8 @@ void deserializesObjectWithReflection() throws IOException { _jsonContentType, mockParseNodeFactory); final var result = - KiotaSerialization.deserialize(_jsonContentType, strValue, TestEntity.class); + KiotaSerialization.deserialize( + _jsonContentType, strValue, TestEntity::createFromDiscriminatorValue); assertEquals("123", result.getId()); }