diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a35bac98f..b861d2e4bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - TypeScript adding index exporting models to fix #870. +- Fixed a bug where JSON serialization would fail on nil properties in Go. ## [0.0.19] - 2022-03-18 diff --git a/abstractions/go/serialization/parsable.go b/abstractions/go/serialization/parsable.go index 47fd4dc102..cbc47cf633 100644 --- a/abstractions/go/serialization/parsable.go +++ b/abstractions/go/serialization/parsable.go @@ -6,8 +6,6 @@ type Parsable interface { Serialize(writer SerializationWriter) error // GetFieldDeserializers returns the deserialization information for this object. GetFieldDeserializers() map[string]func(interface{}, ParseNode) error - // IsNil returns whether the current object is nil or not. - IsNil() bool } // ParsableFactory is a factory for creating Parsable. diff --git a/serialization/go/json/json_serialization_writer.go b/serialization/go/json/json_serialization_writer.go index 93b531331b..3bfefc0729 100644 --- a/serialization/go/json/json_serialization_writer.go +++ b/serialization/go/json/json_serialization_writer.go @@ -243,7 +243,7 @@ func (w *JsonSerializationWriter) WriteByteArrayValue(key string, value []byte) // WriteObjectValue writes a Parsable value to underlying the byte array. func (w *JsonSerializationWriter) WriteObjectValue(key string, item absser.Parsable) error { - if !item.IsNil() { + if item != nil { if key != "" { w.writePropertyName(key) } diff --git a/src/Kiota.Builder/CodeDOM/CodeMethod.cs b/src/Kiota.Builder/CodeDOM/CodeMethod.cs index 56a782e34d..799a03a097 100644 --- a/src/Kiota.Builder/CodeDOM/CodeMethod.cs +++ b/src/Kiota.Builder/CodeDOM/CodeMethod.cs @@ -20,7 +20,6 @@ public enum CodeMethodKind RequestBuilderBackwardCompatibility, RequestBuilderWithParameters, RawUrlConstructor, - NullCheck, CommandBuilder, /// /// The method to be used during deserialization with the discriminator property to get a new instance of the target type. diff --git a/src/Kiota.Builder/Refiners/GoRefiner.cs b/src/Kiota.Builder/Refiners/GoRefiner.cs index 0093e172fe..4354b71303 100644 --- a/src/Kiota.Builder/Refiners/GoRefiner.cs +++ b/src/Kiota.Builder/Refiners/GoRefiner.cs @@ -29,9 +29,6 @@ public override void Refine(CodeNamespace generatedCode) generatedCode, _configuration.UsesBackingStore ); - AddNullCheckMethods( - generatedCode - ); AddRawUrlConstructorOverload( generatedCode ); @@ -170,21 +167,6 @@ private static void ReplaceExecutorAndGeneratorParametersByParameterSets(CodeEle } CrawlTree(currentElement, ReplaceExecutorAndGeneratorParametersByParameterSets); } - private static void AddNullCheckMethods(CodeElement currentElement) { - if(currentElement is CodeClass currentClass && currentClass.IsOfKind(CodeClassKind.Model)) { - currentClass.AddMethod(new CodeMethod { - Name = "IsNil", - IsAsync = false, - Kind = CodeMethodKind.NullCheck, - ReturnType = new CodeType { - Name = "boolean", - IsExternal = true, - IsNullable = false, - }, - }); - } - CrawlTree(currentElement, AddNullCheckMethods); - } private static void RemoveModelPropertiesThatDependOnSubNamespaces(CodeElement currentElement) { if(currentElement is CodeClass currentClass && currentClass.IsOfKind(CodeClassKind.Model) && diff --git a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs index 474f293c1a..9daca8f898 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs @@ -72,8 +72,6 @@ protected virtual void HandleMethodKind(CodeMethod codeElement, LanguageWriter w throw new InvalidOperationException("getters and setters are automatically added on fields in dotnet"); case CodeMethodKind.RequestBuilderBackwardCompatibility: throw new InvalidOperationException("RequestBuilderBackwardCompatibility is not supported as the request builders are implemented by properties."); - case CodeMethodKind.NullCheck: - throw new InvalidOperationException("NullChecks are not required in C#"); case CodeMethodKind.CommandBuilder: var origParams = codeElement.OriginalMethod?.Parameters ?? codeElement.Parameters; requestBodyParam = origParams.OfKind(CodeParameterKind.RequestBody); diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index cdcf2fce2b..84a82e6753 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -70,9 +70,6 @@ public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter wri case CodeMethodKind.RequestBuilderWithParameters: WriteRequestBuilderBody(parentClass, codeElement, writer); break; - case CodeMethodKind.NullCheck: - WriteNullCheckBody(writer); - break; case CodeMethodKind.Factory: WriteFactoryMethodBody(codeElement, writer); break; @@ -116,10 +113,6 @@ private void WriteMethodDocumentation(CodeMethod code, string methodName, Langua if(!string.IsNullOrEmpty(code.Description)) conventions.WriteShortDescription($"{methodName.ToFirstCharacterUpperCase()} {code.Description.ToFirstCharacterLowerCase()}", writer); } - private static void WriteNullCheckBody(LanguageWriter writer) - { - writer.WriteLine("return m == nil"); - } private const string TempParamsVarName = "urlParams"; private static void WriteRawUrlConstructorBody(CodeClass parentClass, CodeMethod codeElement, LanguageWriter writer) { @@ -185,8 +178,7 @@ private void WriteMethodPrototype(CodeMethod code, LanguageWriter writer, string CodeMethodKind.Deserializer, CodeMethodKind.RequestBuilderWithParameters, CodeMethodKind.RequestBuilderBackwardCompatibility, - CodeMethodKind.RawUrlConstructor, - CodeMethodKind.NullCheck) || code.IsAsync ? + CodeMethodKind.RawUrlConstructor) || code.IsAsync ? string.Empty : "error"; if(!string.IsNullOrEmpty(finalReturnType) && !string.IsNullOrEmpty(errorDeclaration)) diff --git a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs index 87f186c2f5..197d4193fb 100644 --- a/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs @@ -74,8 +74,6 @@ public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter wri break; case CodeMethodKind.RequestBuilderBackwardCompatibility: throw new InvalidOperationException("RequestBuilderBackwardCompatibility is not supported as the request builders are implemented by properties."); - case CodeMethodKind.NullCheck: - throw new InvalidOperationException("NullChecks are not required in Java"); case CodeMethodKind.Factory: WriteFactoryMethodBody(codeElement, writer); break;