You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc
+6-8Lines changed: 6 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -376,14 +376,14 @@ Kotlin::
376
376
[source,kotlin]
377
377
----
378
378
data class MathReasoning(
379
-
@get:JsonProperty(required = true, value = "steps") val steps: Steps,
380
-
@get:JsonProperty(required = true, value = "final_answer") val finalAnswer: String) {
379
+
val steps: Steps,
380
+
@get:JsonProperty(value = "final_answer") val finalAnswer: String) {
381
381
382
-
data class Steps(@get:JsonProperty(required = true, value = "items") val items: Array<Items>) {
382
+
data class Steps(val items: Array<Items>) {
383
383
384
384
data class Items(
385
-
@get:JsonProperty(required = true, value = "explanation") val explanation: String,
386
-
@get:JsonProperty(required = true, value = "output") val output: String)
385
+
val explanation: String,
386
+
val output: String)
387
387
}
388
388
}
389
389
@@ -405,9 +405,7 @@ val mathReasoning = outputConverter.convert(content)
405
405
======
406
406
--
407
407
408
-
NOTE: Ensure you use the `@JsonProperty(required = true,...)` annotation (`@get:JsonProperty(required = true,...)` with Kotlin in order to generate the annotation on the related getters, see link:https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets[related documentation]).
409
-
This is crucial for generating a schema that accurately marks fields as `required`.
410
-
Although this is optional for JSON Schema, OpenAI link:https://platform.openai.com/docs/guides/structured-outputs/all-fields-must-be-required[mandates] it for the structured response to function correctly.
408
+
NOTE: Although this is optional for JSON Schema, OpenAI link:https://platform.openai.com/docs/guides/structured-outputs/all-fields-must-be-required#all-fields-must-be-required[mandates] required fields for the structured response to function correctly. Kotlin reflection is used to infer which property are required or not based on the nullability of types and default values of parameters, so for most use case `@get:JsonProperty(required = true)` is not needed. `@get:JsonProperty(value = "custom_name")` can be useful to customize the property name. Make sure to generate the annotation on the related getters with this `@get:` syntax, see link:https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets[related documentation].
0 commit comments