Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Union Type #123

Merged
merged 8 commits into from
May 11, 2024
Merged

Add support to Union Type #123

merged 8 commits into from
May 11, 2024

Conversation

miku1958
Copy link
Collaborator

@miku1958 miku1958 commented May 10, 2024

Add support to union type like string | boolean
Swift uses enum,

public enum UnionType: Codable {
  case string(_ value: String)
  case double(_ value: Double)
  case bool(_ value: Bool)
  case numEnum(_ value: NumEnum)
  case defaultEnum(_ value: DefaultEnum)
}

Kotlin uses sealed class.

sealed class UnionType(val value: Any) {
    data class StringValue(val value: String) : UnionType()
    data class FloatValue(val value: Float) : UnionType()
    data class BooleanValue(val value: Boolean) : UnionType()
    data class NumEnumValue(val value: NumEnum) : UnionType()
    data class DefaultEnumValue(val value: DefaultEnum) : UnionType()
}

Old UnionType is renamed to LiteralType

@miku1958 miku1958 changed the title Add support to Type Union Add support to Union Type May 10, 2024
@miku1958 miku1958 enabled auto-merge (squash) May 10, 2024 13:31
@miku1958 miku1958 merged commit e94bff6 into main May 11, 2024
5 checks passed
@miku1958 miku1958 deleted the TypeUnion branch May 11, 2024 02:15
Copy link
Collaborator

@Foolment Foolment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel ok to merge

// Ignore the exception and try the next type
}
try {
return OverriddenFullSizeMembersUnionTypeType.StringForStringDictionaryValue(context.deserialize(json, Map<String, String>::class.java))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be more types, but I think it's ok right now, we can add more when we need. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants