@@ -6,22 +6,12 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter
66import com.fasterxml.jackson.annotation.JsonAnySetter
77import com.fasterxml.jackson.annotation.JsonCreator
88import com.fasterxml.jackson.annotation.JsonProperty
9- import com.fasterxml.jackson.core.JsonGenerator
10- import com.fasterxml.jackson.core.ObjectCodec
11- import com.fasterxml.jackson.databind.JsonNode
12- import com.fasterxml.jackson.databind.SerializerProvider
13- import com.fasterxml.jackson.databind.annotation.JsonDeserialize
14- import com.fasterxml.jackson.databind.annotation.JsonSerialize
15- import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
16- import com.withorb.api.core.BaseDeserializer
17- import com.withorb.api.core.BaseSerializer
189import com.withorb.api.core.Enum
1910import com.withorb.api.core.ExcludeMissing
2011import com.withorb.api.core.JsonField
2112import com.withorb.api.core.JsonMissing
2213import com.withorb.api.core.JsonValue
2314import com.withorb.api.core.checkRequired
24- import com.withorb.api.core.getOrThrow
2515import com.withorb.api.core.toImmutable
2616import com.withorb.api.errors.OrbInvalidDataException
2717import java.util.Collections
@@ -1172,175 +1162,6 @@ private constructor(
11721162 override fun toString () = value.toString()
11731163 }
11741164
1175- /* * The configuration for the rate of the price currency to the invoicing currency. */
1176- @JsonDeserialize(using = ConversionRateConfig .Deserializer ::class )
1177- @JsonSerialize(using = ConversionRateConfig .Serializer ::class )
1178- class ConversionRateConfig
1179- private constructor (
1180- private val unit: UnitConversionRateConfig ? = null ,
1181- private val tiered: TieredConversionRateConfig ? = null ,
1182- private val _json : JsonValue ? = null ,
1183- ) {
1184-
1185- fun unit (): UnitConversionRateConfig ? = unit
1186-
1187- fun tiered (): TieredConversionRateConfig ? = tiered
1188-
1189- fun isUnit (): Boolean = unit != null
1190-
1191- fun isTiered (): Boolean = tiered != null
1192-
1193- fun asUnit (): UnitConversionRateConfig = unit.getOrThrow(" unit" )
1194-
1195- fun asTiered (): TieredConversionRateConfig = tiered.getOrThrow(" tiered" )
1196-
1197- fun _json (): JsonValue ? = _json
1198-
1199- fun <T > accept (visitor : Visitor <T >): T =
1200- when {
1201- unit != null -> visitor.visitUnit(unit)
1202- tiered != null -> visitor.visitTiered(tiered)
1203- else -> visitor.unknown(_json )
1204- }
1205-
1206- private var validated: Boolean = false
1207-
1208- fun validate (): ConversionRateConfig = apply {
1209- if (validated) {
1210- return @apply
1211- }
1212-
1213- accept(
1214- object : Visitor <Unit > {
1215- override fun visitUnit (unit : UnitConversionRateConfig ) {
1216- unit.validate()
1217- }
1218-
1219- override fun visitTiered (tiered : TieredConversionRateConfig ) {
1220- tiered.validate()
1221- }
1222- }
1223- )
1224- validated = true
1225- }
1226-
1227- fun isValid (): Boolean =
1228- try {
1229- validate()
1230- true
1231- } catch (e: OrbInvalidDataException ) {
1232- false
1233- }
1234-
1235- /* *
1236- * Returns a score indicating how many valid values are contained in this object
1237- * recursively.
1238- *
1239- * Used for best match union deserialization.
1240- */
1241- internal fun validity (): Int =
1242- accept(
1243- object : Visitor <Int > {
1244- override fun visitUnit (unit : UnitConversionRateConfig ) = unit.validity()
1245-
1246- override fun visitTiered (tiered : TieredConversionRateConfig ) = tiered.validity()
1247-
1248- override fun unknown (json : JsonValue ? ) = 0
1249- }
1250- )
1251-
1252- override fun equals (other : Any? ): Boolean {
1253- if (this == = other) {
1254- return true
1255- }
1256-
1257- return other is ConversionRateConfig && unit == other.unit && tiered == other.tiered
1258- }
1259-
1260- override fun hashCode (): Int = Objects .hash(unit, tiered)
1261-
1262- override fun toString (): String =
1263- when {
1264- unit != null -> " ConversionRateConfig{unit=$unit }"
1265- tiered != null -> " ConversionRateConfig{tiered=$tiered }"
1266- _json != null -> " ConversionRateConfig{_unknown=$_json }"
1267- else -> throw IllegalStateException (" Invalid ConversionRateConfig" )
1268- }
1269-
1270- companion object {
1271-
1272- fun ofUnit (unit : UnitConversionRateConfig ) = ConversionRateConfig (unit = unit)
1273-
1274- fun ofTiered (tiered : TieredConversionRateConfig ) = ConversionRateConfig (tiered = tiered)
1275- }
1276-
1277- /* *
1278- * An interface that defines how to map each variant of [ConversionRateConfig] to a value of
1279- * type [T].
1280- */
1281- interface Visitor <out T > {
1282-
1283- fun visitUnit (unit : UnitConversionRateConfig ): T
1284-
1285- fun visitTiered (tiered : TieredConversionRateConfig ): T
1286-
1287- /* *
1288- * Maps an unknown variant of [ConversionRateConfig] to a value of type [T].
1289- *
1290- * An instance of [ConversionRateConfig] can contain an unknown variant if it was
1291- * deserialized from data that doesn't match any known variant. For example, if the SDK
1292- * is on an older version than the API, then the API may respond with new variants that
1293- * the SDK is unaware of.
1294- *
1295- * @throws OrbInvalidDataException in the default implementation.
1296- */
1297- fun unknown (json : JsonValue ? ): T {
1298- throw OrbInvalidDataException (" Unknown ConversionRateConfig: $json " )
1299- }
1300- }
1301-
1302- internal class Deserializer :
1303- BaseDeserializer <ConversionRateConfig >(ConversionRateConfig ::class ) {
1304-
1305- override fun ObjectCodec.deserialize (node : JsonNode ): ConversionRateConfig {
1306- val json = JsonValue .fromJsonNode(node)
1307- val conversionRateType = json.asObject()?.get(" conversion_rate_type" )?.asString()
1308-
1309- when (conversionRateType) {
1310- " unit" -> {
1311- return tryDeserialize(node, jacksonTypeRef<UnitConversionRateConfig >())
1312- ?.let { ConversionRateConfig (unit = it, _json = json) }
1313- ? : ConversionRateConfig (_json = json)
1314- }
1315- " tiered" -> {
1316- return tryDeserialize(node, jacksonTypeRef<TieredConversionRateConfig >())
1317- ?.let { ConversionRateConfig (tiered = it, _json = json) }
1318- ? : ConversionRateConfig (_json = json)
1319- }
1320- }
1321-
1322- return ConversionRateConfig (_json = json)
1323- }
1324- }
1325-
1326- internal class Serializer :
1327- BaseSerializer <ConversionRateConfig >(ConversionRateConfig ::class ) {
1328-
1329- override fun serialize (
1330- value : ConversionRateConfig ,
1331- generator : JsonGenerator ,
1332- provider : SerializerProvider ,
1333- ) {
1334- when {
1335- value.unit != null -> generator.writeObject(value.unit)
1336- value.tiered != null -> generator.writeObject(value.tiered)
1337- value._json != null -> generator.writeObject(value._json )
1338- else -> throw IllegalStateException (" Invalid ConversionRateConfig" )
1339- }
1340- }
1341- }
1342- }
1343-
13441165 /* *
13451166 * User-specified key/value pairs for the resource. Individual keys can be removed by setting
13461167 * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to
0 commit comments