diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8ed5db875d..04f53d878b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed a bug where serialize method will not write additional data when backingStore is enabled for java. [#3643](https://github.com/microsoft/kiota/pull/3643)
- Fixed a bug where paths with parameters in the same position but different names would make generation fail. [#3756](https://github.com/microsoft/kiota/issues/3756)
- Fixed a bug where a property named constructor would make generation fail. [#3756](https://github.com/microsoft/kiota/issues/3756)
+- Removed reflection for Java enum deserialization. [microsoft/kiota-java#843](https://github.com/microsoft/kiota-java/pull/843)
## [1.8.2] - 2023-11-08
diff --git a/it/java/basic/pom.xml b/it/java/basic/pom.xml
index 82f41bd4ba..f217e83c5f 100644
--- a/it/java/basic/pom.xml
+++ b/it/java/basic/pom.xml
@@ -15,7 +15,7 @@
UTF-8
UTF-8
- 0.9.0
+ 0.10.0
diff --git a/it/java/pom.xml b/it/java/pom.xml
index 95b65a018b..3edaaa1d7b 100644
--- a/it/java/pom.xml
+++ b/it/java/pom.xml
@@ -15,7 +15,7 @@
UTF-8
UTF-8
- 0.9.0
+ 0.10.0
diff --git a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs
index 80699e2c72..b1d10598d9 100644
--- a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs
+++ b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs
@@ -500,9 +500,9 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ
writer.WriteLine($"{errorMappingVarName}.put(\"{errorMapping.Key.ToUpperInvariant()}\", {errorMapping.Value.Name}::{FactoryMethodName});");
}
}
- var factoryParameter = codeElement.ReturnType is CodeType returnCodeType && returnCodeType.TypeDefinition is CodeClass ? $"{returnType}::{FactoryMethodName}" : $"{returnType}.class";
+ var factoryParameter = GetSendRequestFactoryParam(returnType, codeElement.ReturnType.AllTypes.First().TypeDefinition is CodeEnum);
var returnPrefix = codeElement.ReturnType.Name.Equals("void", StringComparison.OrdinalIgnoreCase) ? string.Empty : "return ";
- writer.WriteLine($"{returnPrefix}this.requestAdapter.{sendMethodName}({RequestInfoVarName}, {factoryParameter}, {errorMappingVarName});");
+ writer.WriteLine($"{returnPrefix}this.requestAdapter.{sendMethodName}({RequestInfoVarName}, {errorMappingVarName}, {factoryParameter});");
}
private string GetSendRequestMethodName(bool isCollection, string returnType, bool isEnum)
{
@@ -519,6 +519,16 @@ private string GetSendRequestMethodName(bool isCollection, string returnType, bo
else if (isCollection) return "sendCollection";
return "send";
}
+ private string GetSendRequestFactoryParam(string returnType, bool isEnum)
+ {
+ if (conventions.PrimitiveTypes.Contains(returnType))
+ return $"{returnType}.class";
+ else if (isEnum)
+ return $"{returnType}::forValue";
+ else
+ return $"{returnType}::{FactoryMethodName}";
+ }
+
private const string RequestInfoVarName = "requestInfo";
private static void WriteGeneratorOrExecutorMethodCall(CodeMethod codeElement, RequestParams requestParams, CodeClass parentClass, LanguageWriter writer, string prefix, CodeMethodKind codeMethodKind)
{
@@ -729,11 +739,15 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me
if (currentType.TypeDefinition == null)
return $"getCollectionOfPrimitiveValues({propertyType.ToFirstCharacterUpperCase()}.class)";
else if (currentType.TypeDefinition is CodeEnum enumType)
- return $"getCollectionOfEnumValues({enumType.Name}.class)";
+ return $"getCollectionOfEnumValues({enumType.Name}::forValue)";
else
return $"getCollectionOfObjectValues({propertyType.ToFirstCharacterUpperCase()}::{FactoryMethodName})";
if (currentType.TypeDefinition is CodeEnum currentEnum)
- return $"getEnum{(currentEnum.Flags ? "Set" : string.Empty)}Value({propertyType.ToFirstCharacterUpperCase()}.class)";
+ {
+ var returnType = propertyType.ToFirstCharacterUpperCase();
+ return $"getEnum{(currentEnum.Flags ? "Set" : string.Empty)}Value({returnType}::forValue)";
+ }
+
}
return propertyType switch
{