Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Support POJO/Java Class for automatic responseSchema generation

未关闭
#764 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@hemasekhar-p 已经在做这个了。

开始于 2026年1月8日。

评估

这个 Issue 还没有评估数据。

描述

priority: p3 type: feature request

Is your feature request related to a problem? Please describe.
I am frustrated when I have to manually define the responseSchema using complex builders, even though I already have well-structured DTO (Data Transfer Object) classes in my Java project.

Currently, the Java SDK requires developers to manually construct a Schema object. This leads to redundant work and high maintenance costs, as any change in the Java class must be manually reflected in the Schema builder. For example, in a project with many complex DTOs, this manual mapping is highly error-prone and degrades the Developer Experience (DX).

Describe the solution you'd like
I would like the GenerateContentConfig.Builder to support an overloaded responseSchema(Class<?> clazz) method. This method should automatically introspect the provided Java class (POJO/Record) and generate the corresponding Schema object.

Desired Usage:

// Instead of manual Schema building
GenerateContentConfig config = GenerateContentConfig.builder()
    .responseMimeType("application/json")
    .responseSchema(MyResponseDto.class) // Passing the DTO class directly
    .build();

The SDK should ideally use reflection or existing Jackson integration to map Java types (String, Integer, List, etc.) to the Gemini Type system.

Describe alternatives you've considered
I have considered the Python Gen AI SDK, which already provides this functionality through Pydantic models. Python developers can simply pass a class to response_schema, and the SDK handles the rest.

Currently, in Java, I have to write a custom utility using jsonschema-generator and map it back to the SDK's Schema object. This feels like a feature that should be natively supported to ensure "Feature Parity" across different language SDKs.

Additional context
Since the SDK already utilizes Jackson (@JsonProperty), implementing this wouldn't necessarily require heavy new dependencies. The implementation could respect Jackson annotations:

  • @JsonPropertyDescription: To populate the description field in the schema.
  • @JsonProperty: To handle custom field naming.

This enhancement would make the Java SDK feel much more "idiomatic" and productive for enterprise-level backend development.

主要语言
Java
星标
398
派生
126
平均合并
1 天 12 小时
30 天内合并 PR
71

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

googleapis/java-genai 的其他 Issue

查看 googleapis/java-genai 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。