@@ -658,7 +658,7 @@ private constructor(
658658 private constructor (
659659 private val eventName: JsonField <String >,
660660 private val idempotencyKey: JsonField <String >,
661- private val properties: JsonValue ,
661+ private val properties: JsonField < Properties > ,
662662 private val timestamp: JsonField <OffsetDateTime >,
663663 private val customerId: JsonField <String >,
664664 private val externalCustomerId: JsonField <String >,
@@ -673,7 +673,9 @@ private constructor(
673673 @JsonProperty(" idempotency_key" )
674674 @ExcludeMissing
675675 idempotencyKey: JsonField <String > = JsonMissing .of(),
676- @JsonProperty(" properties" ) @ExcludeMissing properties: JsonValue = JsonMissing .of(),
676+ @JsonProperty(" properties" )
677+ @ExcludeMissing
678+ properties: JsonField <Properties > = JsonMissing .of(),
677679 @JsonProperty(" timestamp" )
678680 @ExcludeMissing
679681 timestamp: JsonField <OffsetDateTime > = JsonMissing .of(),
@@ -714,8 +716,11 @@ private constructor(
714716 /* *
715717 * A dictionary of custom properties. Values in this dictionary must be numeric, boolean, or
716718 * strings. Nested dictionaries are disallowed.
719+ *
720+ * @throws OrbInvalidDataException if the JSON field has an unexpected type or is
721+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
717722 */
718- @JsonProperty( " properties " ) @ExcludeMissing fun _properties (): JsonValue = properties
723+ fun properties (): Properties = properties.getRequired( " properties " )
719724
720725 /* *
721726 * An ISO 8601 format date with no timezone offset (i.e. UTC). This should represent the
@@ -761,6 +766,15 @@ private constructor(
761766 @ExcludeMissing
762767 fun _idempotencyKey (): JsonField <String > = idempotencyKey
763768
769+ /* *
770+ * Returns the raw JSON value of [properties].
771+ *
772+ * Unlike [properties], this method doesn't throw if the JSON field has an unexpected type.
773+ */
774+ @JsonProperty(" properties" )
775+ @ExcludeMissing
776+ fun _properties (): JsonField <Properties > = properties
777+
764778 /* *
765779 * Returns the raw JSON value of [timestamp].
766780 *
@@ -822,7 +836,7 @@ private constructor(
822836
823837 private var eventName: JsonField <String >? = null
824838 private var idempotencyKey: JsonField <String >? = null
825- private var properties: JsonValue ? = null
839+ private var properties: JsonField < Properties > ? = null
826840 private var timestamp: JsonField <OffsetDateTime >? = null
827841 private var customerId: JsonField <String > = JsonMissing .of()
828842 private var externalCustomerId: JsonField <String > = JsonMissing .of()
@@ -874,7 +888,18 @@ private constructor(
874888 * A dictionary of custom properties. Values in this dictionary must be numeric,
875889 * boolean, or strings. Nested dictionaries are disallowed.
876890 */
877- fun properties (properties : JsonValue ) = apply { this .properties = properties }
891+ fun properties (properties : Properties ) = properties(JsonField .of(properties))
892+
893+ /* *
894+ * Sets [Builder.properties] to an arbitrary JSON value.
895+ *
896+ * You should usually call [Builder.properties] with a well-typed [Properties] value
897+ * instead. This method is primarily for setting the field to an undocumented or not yet
898+ * supported value.
899+ */
900+ fun properties (properties : JsonField <Properties >) = apply {
901+ this .properties = properties
902+ }
878903
879904 /* *
880905 * An ISO 8601 format date with no timezone offset (i.e. UTC). This should represent the
@@ -988,6 +1013,7 @@ private constructor(
9881013
9891014 eventName()
9901015 idempotencyKey()
1016+ properties().validate()
9911017 timestamp()
9921018 customerId()
9931019 externalCustomerId()
@@ -1012,10 +1038,119 @@ private constructor(
10121038 internal fun validity (): Int =
10131039 (if (eventName.asKnown().isPresent) 1 else 0 ) +
10141040 (if (idempotencyKey.asKnown().isPresent) 1 else 0 ) +
1041+ (properties.asKnown().getOrNull()?.validity() ? : 0 ) +
10151042 (if (timestamp.asKnown().isPresent) 1 else 0 ) +
10161043 (if (customerId.asKnown().isPresent) 1 else 0 ) +
10171044 (if (externalCustomerId.asKnown().isPresent) 1 else 0 )
10181045
1046+ /* *
1047+ * A dictionary of custom properties. Values in this dictionary must be numeric, boolean, or
1048+ * strings. Nested dictionaries are disallowed.
1049+ */
1050+ class Properties
1051+ @JsonCreator
1052+ private constructor (
1053+ @com.fasterxml.jackson.annotation.JsonValue
1054+ private val additionalProperties: Map <String , JsonValue >
1055+ ) {
1056+
1057+ @JsonAnyGetter
1058+ @ExcludeMissing
1059+ fun _additionalProperties (): Map <String , JsonValue > = additionalProperties
1060+
1061+ fun toBuilder () = Builder ().from(this )
1062+
1063+ companion object {
1064+
1065+ /* * Returns a mutable builder for constructing an instance of [Properties]. */
1066+ @JvmStatic fun builder () = Builder ()
1067+ }
1068+
1069+ /* * A builder for [Properties]. */
1070+ class Builder internal constructor() {
1071+
1072+ private var additionalProperties: MutableMap <String , JsonValue > = mutableMapOf ()
1073+
1074+ @JvmSynthetic
1075+ internal fun from (properties : Properties ) = apply {
1076+ additionalProperties = properties.additionalProperties.toMutableMap()
1077+ }
1078+
1079+ fun additionalProperties (additionalProperties : Map <String , JsonValue >) = apply {
1080+ this .additionalProperties.clear()
1081+ putAllAdditionalProperties(additionalProperties)
1082+ }
1083+
1084+ fun putAdditionalProperty (key : String , value : JsonValue ) = apply {
1085+ additionalProperties.put(key, value)
1086+ }
1087+
1088+ fun putAllAdditionalProperties (additionalProperties : Map <String , JsonValue >) =
1089+ apply {
1090+ this .additionalProperties.putAll(additionalProperties)
1091+ }
1092+
1093+ fun removeAdditionalProperty (key : String ) = apply {
1094+ additionalProperties.remove(key)
1095+ }
1096+
1097+ fun removeAllAdditionalProperties (keys : Set <String >) = apply {
1098+ keys.forEach(::removeAdditionalProperty)
1099+ }
1100+
1101+ /* *
1102+ * Returns an immutable instance of [Properties].
1103+ *
1104+ * Further updates to this [Builder] will not mutate the returned instance.
1105+ */
1106+ fun build (): Properties = Properties (additionalProperties.toImmutable())
1107+ }
1108+
1109+ private var validated: Boolean = false
1110+
1111+ fun validate (): Properties = apply {
1112+ if (validated) {
1113+ return @apply
1114+ }
1115+
1116+ validated = true
1117+ }
1118+
1119+ fun isValid (): Boolean =
1120+ try {
1121+ validate()
1122+ true
1123+ } catch (e: OrbInvalidDataException ) {
1124+ false
1125+ }
1126+
1127+ /* *
1128+ * Returns a score indicating how many valid values are contained in this object
1129+ * recursively.
1130+ *
1131+ * Used for best match union deserialization.
1132+ */
1133+ @JvmSynthetic
1134+ internal fun validity (): Int =
1135+ additionalProperties.count { (_, value) -> ! value.isNull() && ! value.isMissing() }
1136+
1137+ override fun equals (other : Any? ): Boolean {
1138+ if (this == = other) {
1139+ return true
1140+ }
1141+
1142+ return /* spotless:off */ other is Properties && additionalProperties == other.additionalProperties /* spotless:on */
1143+ }
1144+
1145+ /* spotless:off */
1146+ private val hashCode: Int by lazy { Objects .hash(additionalProperties) }
1147+ /* spotless:on */
1148+
1149+ override fun hashCode (): Int = hashCode
1150+
1151+ override fun toString () = " Properties{additionalProperties=$additionalProperties }"
1152+ }
1153+
10191154 override fun equals (other : Any? ): Boolean {
10201155 if (this == = other) {
10211156 return true
0 commit comments