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

更安全的读取 JSON #23

Merged
merged 1 commit into from
Sep 16, 2024
Merged

更安全的读取 JSON #23

merged 1 commit into from
Sep 16, 2024

Conversation

zhongl
Copy link
Member

@zhongl zhongl commented Sep 16, 2024

注意:

type Foo = Safety:
  val bar: Double

bar 类型发生变化时, 比如为 String,会导致 ClassCastException ,且在代码混淆后不易排查问题。

这个问题的解受限于 Types Structural 本身的设计,暂无法解决。

Comment on lines +10 to +12
if js.isUndefined(v) then throw NoSuchFieldException(name) else v
case t =>
throw UnsupportedOperationException(s"get $name from $t")
Copy link
Member Author

Choose a reason for hiding this comment

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

用异常信息明确提示:

  • 字段不存在,或
  • 非对象类型

@zhongl zhongl merged commit 30a0f6b into main Sep 16, 2024
1 check passed
@zhongl zhongl deleted the refa/read branch September 16, 2024 09:15
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.

1 participant