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

Deserializing ResponseInputItem results in unknown state

Chiusa
#584 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
java, kotlin
Ambito
api

Direzione di ricerca

Inizia dal percorso di deserializzazione di ResponseInputItem.Message e confrontalo con il percorso di ResponseOutputMessage, utilizzando la riproduzione fornita testSerializeInputItem. Verifica che i valori serializzati e deserializzati di ResponseInputItem.Message risultino uguali senza diventare unknown; il test output-item esistente fornisce un caso di confronto funzionante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug spec

Hey there! 👋

I'm working with the OpenAI Java SDK for a couple of days now and really like it. The general design of the library is fantastic and I'm having quite a lot fun working with it. Thanks! 👍

I stumbled upon an issue which I think is a bug. Let me first clarify about my goals: I'm using the Responses API part of the library to implement Chat-Bot like conversations. My requirement is to use ResponseCreateParams.builder().store(false) and instead serialize conversation state locally by myself.

Here's an example of what I do:

val jsonMapper = jsonMapper()
val inputItems: List<ResponseInputItem> = ...
val jsonData = jsonMapper.writeValueAsString(inputItems)
// store jsonData locally

// later:
val deserializedInputItems = jsonMapper.readValue(nativeData, object : TypeReference<MutableList<ResponseInputItem>>() {})
// attach new user message and continue conversation

This works pretty well. However I've noticed the following behavior:

When a ResponseInputItem from a ResponseInputItem.Message gets serialized and deserialized again, it's in an unknown state. The message field is null but the _json() field still holds the correct structured data from the original message.

Here's are a Kotlin Test to demonstrate the behavior:

❌ This test fails with v3.0.3

@Test
fun testSerializeInputItem() {
    // given
    val message = ResponseInputItem.Message.builder()
        .role(ResponseInputItem.Message.Role.USER)
        .addInputTextContent("Test")
        .build()
    val inputItem1 = ResponseInputItem.ofMessage(message)

    // when
    val jsonMapper = jsonMapper()
    val inputItemJson = jsonMapper.writeValueAsString(inputItem1)
    val inputItem2 = jsonMapper.readValue(inputItemJson, ResponseInputItem::class.java)

    // then
    Assertions.assertEquals(inputItem1, inputItem2)
}

Test fails:

Expected :ResponseInputItem{message=Message{content=[ResponseInputContent{inputText=ResponseInputText{text=Test, type=input_text, additionalProperties={}}}], role=user, status=, type=, additionalProperties={}}}
Actual   :ResponseInputItem{_unknown={content=[{text=Test, type=input_text}], role=user}}

I couldn't reproduce this issue with other types of ResponseInputItems, e.g. for ResponseOutputMessage the test succeeds:

🟢 This test succeeds with v3.0.3

@Test
fun testSerializeOutputItem() {
    val message = ResponseOutputMessage.builder()
        .id("my_id")
        .status(ResponseOutputMessage.Status.COMPLETED)
        .addContent(
            ResponseOutputText.builder()
                .text("Test")
                .annotations(emptyList())
                .build()
        )
        .build()
    val inputItem1 = ResponseInputItem.ofResponseOutputMessage(message)

    val jsonMapper = jsonMapper()
    val inputItemJson = jsonMapper.writeValueAsString(inputItem1)

    val inputItem2 = jsonMapper.readValue(inputItemJson, ResponseInputItem::class.java)
    Assertions.assertEquals(inputItem1, inputItem2)
}

Could you please clarify if this a bug? Or am I doing something wrong / unintended here?

Lingua principale
Kotlin
Stelle
1.5k
Fork
266
Merge medio
10h 11m
PR unite (30g)
141

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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 openai/openai-java

Tutte le issue di openai/openai-java

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.