Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Support POJO/Java Class for automatic responseSchema generation

Aperta
#764 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@hemasekhar-p ci sta già lavorando.

Dal 8/1/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.

Lingua principale
Java
Stelle
398
Fork
126
Merge medio
1g 12h
PR unite (30g)
71

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di googleapis/java-genai

Tutte le issue di googleapis/java-genai

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.