@@ -8,8 +8,10 @@ import com.fasterxml.jackson.annotation.JsonCreator
88import com.fasterxml.jackson.annotation.JsonProperty
99import dev.arcade.core.Enum
1010import dev.arcade.core.ExcludeMissing
11+ import dev.arcade.core.JsonArray
1112import dev.arcade.core.JsonField
1213import dev.arcade.core.JsonMissing
14+ import dev.arcade.core.JsonObject
1315import dev.arcade.core.JsonValue
1416import dev.arcade.core.checkKnown
1517import dev.arcade.core.checkRequired
@@ -467,6 +469,78 @@ private constructor(
467469 */
468470 @JsonProperty(" value" ) @ExcludeMissing fun _value (): JsonValue = value
469471
472+ // -------------------------------------------------------------------------
473+ // Start of manually added code
474+ // -------------------------------------------------------------------------
475+
476+ /* *
477+ * Returns an [Optional] containing the output value as a `Map<String, JsonValue>`, or an
478+ * empty [Optional] if the value is not a JSON object.
479+ *
480+ * Example usage:
481+ * ```java
482+ * Map<String, JsonValue> result = response.output()
483+ * .flatMap(Output::valueAsObject)
484+ * .orElse(Map.of());
485+ * ```
486+ */
487+ fun valueAsObject (): Optional <Map <String , JsonValue >> =
488+ when (value) {
489+ is JsonObject -> Optional .of(value.values)
490+ else -> Optional .empty()
491+ }
492+
493+ /* *
494+ * Returns the output value as a `Map<String, JsonValue>`, or an empty map if the value is
495+ * not a JSON object.
496+ *
497+ * Example usage:
498+ * ```java
499+ * Map<String, JsonValue> result = output.valueAsObjectOrEmpty();
500+ * ```
501+ */
502+ fun valueAsObjectOrEmpty (): Map <String , JsonValue > =
503+ when (value) {
504+ is JsonObject -> value.values
505+ else -> emptyMap()
506+ }
507+
508+ /* *
509+ * Returns an [Optional] containing the output value as a `List<JsonValue>`, or an empty
510+ * [Optional] if the value is not a JSON array.
511+ *
512+ * Example usage:
513+ * ```java
514+ * List<JsonValue> items = response.output()
515+ * .flatMap(Output::valueAsArray)
516+ * .orElse(List.of());
517+ * ```
518+ */
519+ fun valueAsArray (): Optional <List <JsonValue >> =
520+ when (value) {
521+ is JsonArray -> Optional .of(value.values)
522+ else -> Optional .empty()
523+ }
524+
525+ /* *
526+ * Returns the output value as a `List<JsonValue>`, or an empty list if the value is not a
527+ * JSON array.
528+ *
529+ * Example usage:
530+ * ```java
531+ * List<JsonValue> items = output.valueAsArrayOrEmpty();
532+ * ```
533+ */
534+ fun valueAsArrayOrEmpty (): List <JsonValue > =
535+ when (value) {
536+ is JsonArray -> value.values
537+ else -> emptyList()
538+ }
539+
540+ // -------------------------------------------------------------------------
541+ // End of manually added code
542+ // -------------------------------------------------------------------------
543+
470544 /* *
471545 * Returns the raw JSON value of [authorization].
472546 *
0 commit comments