diff --git a/docs/generators/go.md b/docs/generators/go.md
index 7120de8ba6b..e6bb365b551 100644
--- a/docs/generators/go.md
+++ b/docs/generators/go.md
@@ -21,6 +21,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
- **false**
- The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
- **true**
- Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true|
|enumClassPrefix|Prefix enum with class name| |false|
|generateInterfaces|Generate interfaces for api classes| |false|
+|generateMarshalJSON|Generate MarshalJSON method| |true|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|isGoSubmodule|whether the generated Go module is a submodule| |false|
|packageName|Go package name (convention: lowercase).| |openapi|
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
index c3b477715d7..670529a733a 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
@@ -433,4 +433,7 @@ public class CodegenConstants {
public static final String FASTAPI_IMPLEMENTATION_PACKAGE = "fastapiImplementationPackage";
public static final String WITH_GO_MOD = "withGoMod";
+
+ public static final String GENERATE_MARSHAL_JSON = "generateMarshalJSON";
+ public static final String GENERATE_MARSHAL_JSON_DESC = "Generate MarshalJSON method";
}
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java
index 38d2513ab3a..50eda6dddad 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java
@@ -50,6 +50,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
protected boolean structPrefix = false;
protected boolean generateInterfaces = false;
protected boolean withGoMod = false;
+ protected boolean generateMarshalJSON = true;
protected String packageName = "openapi";
protected Set numberTypes;
@@ -667,7 +668,12 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
model.isNullable = true;
model.anyOf.remove("nil");
}
+
+ if (generateMarshalJSON) {
+ model.vendorExtensions.put("x-go-generate-marshal-json", true);
+ }
}
+
// recursively add import for mapping one type to multiple imports
List