-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for union to enum (#117)
* Add support for union to enum * rename * reuse path for unique name & fix shared types is not in shared file * lint * fix: kotlin shared types is missing * fix: align usage with TupleType * style: rename members * fix: remove unused content * feature: add nullable check * fix: revert unused content * doc: update document * fix: remove kind from LiteralType * fix: remove type cast of namedType * fix: revert LiteralType from parseLiteralNode * fix: Add support for strings that look like numbers
- Loading branch information
Showing
15 changed files
with
498 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright (c) 2021. | ||
* Microsoft Corporation. All rights reserved. | ||
* | ||
* | ||
* This file is automatically generated | ||
* Please DO NOT modify | ||
*/ | ||
|
||
package com.microsoft.office.outlook.rooster.web.bridge | ||
|
||
import java.lang.reflect.Type | ||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonDeserializer | ||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonPrimitive | ||
import com.google.gson.JsonSerializationContext | ||
import com.google.gson.JsonSerializer | ||
import com.google.gson.annotations.SerializedName | ||
|
||
|
||
data class OverriddenFullSize( | ||
@JvmField val size: Float, | ||
@JvmField val count: Int, | ||
@JvmField val stringEnum: StringEnum, | ||
@JvmField val numEnum: NumEnum, | ||
@JvmField val defEnum: DefaultEnum, | ||
@JvmField val stringUnion: OverriddenFullSizeMembersStringUnionType, | ||
@JvmField val numberStringUnion: OverriddenFullSizeMembersNumberStringUnionType, | ||
@JvmField val nullableStringUnion: OverriddenFullSizeMembersNullableStringUnionType?, | ||
@JvmField val numUnion1: OverriddenFullSizeMembersNumUnion1Type, | ||
@JvmField val foo: OverriddenFullSizeMembersFooType, | ||
@JvmField val width: Float, | ||
@JvmField val height: Float, | ||
@JvmField val scale: Float, | ||
@JvmField val member: NumEnum = NumEnum.ONE, | ||
) | ||
|
||
enum class NumEnum(val value: Int) { | ||
ONE(1), | ||
TWO(2); | ||
|
||
companion object { | ||
fun find(value: Int) = values().find { it.value == value } | ||
} | ||
} | ||
|
||
class NumEnumTypeAdapter : JsonSerializer<NumEnum>, JsonDeserializer<NumEnum> { | ||
override fun serialize(obj: NumEnum, type: Type, context: JsonSerializationContext): JsonElement { | ||
return JsonPrimitive(obj.value) | ||
} | ||
|
||
override fun deserialize(json: JsonElement, type: Type, context: JsonDeserializationContext): NumEnum? { | ||
return NumEnum.find(json.asInt) | ||
} | ||
} | ||
|
||
enum class StringEnum { | ||
@SerializedName("a") A, | ||
@SerializedName("b") B | ||
} | ||
|
||
enum class DefaultEnum(val value: Int) { | ||
DEFAULT_VALUE_C(0), | ||
DEFAULT_VALUE_D(1); | ||
|
||
companion object { | ||
fun find(value: Int) = values().find { it.value == value } | ||
} | ||
} | ||
|
||
class DefaultEnumTypeAdapter : JsonSerializer<DefaultEnum>, JsonDeserializer<DefaultEnum> { | ||
override fun serialize(obj: DefaultEnum, type: Type, context: JsonSerializationContext): JsonElement { | ||
return JsonPrimitive(obj.value) | ||
} | ||
|
||
override fun deserialize(json: JsonElement, type: Type, context: JsonDeserializationContext): DefaultEnum? { | ||
return DefaultEnum.find(json.asInt) | ||
} | ||
} | ||
|
||
enum class OverriddenFullSizeMembersStringUnionType { | ||
@SerializedName("A1") A1, | ||
@SerializedName("B1") B1 | ||
} | ||
|
||
enum class OverriddenFullSizeMembersNumberStringUnionType { | ||
@SerializedName("11") _11, | ||
@SerializedName("21") _21 | ||
} | ||
|
||
enum class OverriddenFullSizeMembersNullableStringUnionType { | ||
@SerializedName("A1") A1, | ||
@SerializedName("B1") B1 | ||
} | ||
|
||
enum class OverriddenFullSizeMembersNumUnion1Type(val value: Int) { | ||
_11(11), | ||
_21(21); | ||
|
||
companion object { | ||
fun find(value: Int) = values().find { it.value == value } | ||
} | ||
} | ||
|
||
class OverriddenFullSizeMembersNumUnion1TypeTypeAdapter : JsonSerializer<OverriddenFullSizeMembersNumUnion1Type>, JsonDeserializer<OverriddenFullSizeMembersNumUnion1Type> { | ||
override fun serialize(obj: OverriddenFullSizeMembersNumUnion1Type, type: Type, context: JsonSerializationContext): JsonElement { | ||
return JsonPrimitive(obj.value) | ||
} | ||
|
||
override fun deserialize(json: JsonElement, type: Type, context: JsonDeserializationContext): OverriddenFullSizeMembersNumUnion1Type? { | ||
return OverriddenFullSizeMembersNumUnion1Type.find(json.asInt) | ||
} | ||
} | ||
|
||
data class OverriddenFullSizeMembersFooType( | ||
@JvmField val stringField: String, | ||
@JvmField val numberField: Float, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.