OpenAPITools/openapi-generator · error · RuntimeException

This library currently only supports gson serialization. Try

Error message

This library currently only supports gson serialization. Try adding '--additional-properties serializationLibrary=gson' to your command.

What it means

processJVMVolleyLibrary hard-requires serializationLibrary=gson: the Volley templates (GsonRequest.mustache, RequestFactory.mustache, ...) are built around gson 2.8.9. The generator-wide default serializationLibrary is moshi, so selecting --library=jvm-volley without explicitly setting gson always throws this RuntimeException during library processing. The Volley library is additionally marked Deprecated in supportedLibraries.

Source

Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java:749

        if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
            if (!additionalProperties.containsKey(ROOM_MODEL_PACKAGE))
                this.setRoomModelPackage(packageName + ".models.room");
            else
                this.setRoomModelPackage(additionalProperties.get(ROOM_MODEL_PACKAGE).toString());
        }
        additionalProperties.put(ROOM_MODEL_PACKAGE, roomModelPackage);

        supportingFiles.add(new SupportingFile("infrastructure/CollectionFormats.kt.mustache", infrastructureFolder, "CollectionFormats.kt"));

        // We have auth related partial files, so they can be overridden, but don't generate them explicitly
        supportingFiles.add(new SupportingFile("request/GsonRequest.mustache", requestFolder, "GsonRequest.kt"));
        supportingFiles.add(new SupportingFile("request/IRequestFactory.mustache", requestFolder, "IRequestFactory.kt"));
        supportingFiles.add(new SupportingFile("request/RequestFactory.mustache", requestFolder, "RequestFactory.kt"));
        supportingFiles.add(new SupportingFile("infrastructure/CollectionFormats.kt.mustache", infrastructureFolder, "CollectionFormats.kt"));

        if (getSerializationLibrary() != SERIALIZATION_LIBRARY_TYPE.gson) {
            throw new RuntimeException("This library currently only supports gson serialization. Try adding '--additional-properties serializationLibrary=gson' to your command.");
        }
        addSupportingSerializerAdapters(infrastructureFolder);
        supportingFiles.remove(new SupportingFile("jvm-common/infrastructure/Serializer.kt.mustache", infrastructureFolder, "Serializer.kt"));

    }

    private void addSupportingSerializerAdapters(final String infrastructureFolder) {
        supportingFiles.add(new SupportingFile("jvm-common/infrastructure/Serializer.kt.mustache", infrastructureFolder, "Serializer.kt"));

        switch (getSerializationLibrary()) {
            case moshi:
                if (enumUnknownDefaultCase) {
                    supportingFiles.add(new SupportingFile("jvm-common/infrastructure/SerializerHelper.kt.mustache", infrastructureFolder, "SerializerHelper.kt"));
                }
                supportingFiles.add(new SupportingFile("jvm-common/infrastructure/ByteArrayAdapter.kt.mustache", infrastructureFolder, "ByteArrayAdapter.kt"));
                supportingFiles.add(new SupportingFile("jvm-common/infrastructure/UUIDAdapter.kt.mustache", infrastructureFolder, "UUIDAdapter.kt"));
                supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateAdapter.kt.mustache", infrastructureFolder, "LocalDateAdapter.kt"));
                supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateTimeAdapter.kt.mustache", infrastructureFolder, "LocalDateTimeAdapter.kt"));

View on GitHub (pinned to fcec517be3)

Solutions

  1. Add `-p serializationLibrary=gson` exactly.
  2. Better: migrate off the deprecated jvm-volley library — jvm-okhttp4 (moshi default) is the maintained JVM client path.

Example fix

# before
openapi-generator-cli generate -g kotlin --library=jvm-volley -i api.yaml
# after
openapi-generator-cli generate -g kotlin --library=jvm-volley -i api.yaml -p serializationLibrary=gson
Defensive patterns

Strategy: validation

Validate before calling

# shell: volley demands gson
if [ "$LIBRARY" = "jvm-volley" ] && [ "${SERIALIZATION_LIBRARY:-moshi}" != "gson" ]; then
  echo "jvm-volley requires serializationLibrary=gson" >&2; exit 2
fi

Try / catch

try {
    DefaultGenerator().opts(clientOptInput).generate()
} catch (e: RuntimeException) {
    throw IllegalStateException("jvm-volley serialization mismatch: ${e.message}", e)
}

Prevention

When it happens

Trigger: `-g kotlin --library=jvm-volley` alone (default moshi → throw); with `-p serializationLibrary=moshi|jackson|kotlinx_serialization` explicitly.

Common situations: Legacy Android pipelines still on Volley; copying a kotlin invocation from a colleague who used okhttp4 defaults and just changing --library.

Related errors


AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22). Data as JSON: /api/errors/a30cc21b3ad1df2a. Report an issue: GitHub.