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

fix #305, Java Double type to float64 get error when null value set #306

Closed
wants to merge 1 commit into from

Conversation

ma642
Copy link

@ma642 ma642 commented Jan 6, 2022

What this PR does:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


fix #305 #305; return zero value float64 when java side set null to Double .

@wongoo
Copy link
Contributor

wongoo commented Jan 6, 2022

@ma642 decoding java Double null to golang float64 zero is not a good idea.
it's better to match from :

  • java Double to golang *float64
  • java Integer to golang *int

@ma642
Copy link
Author

ma642 commented Jan 6, 2022

我觉得float64(0) --》 Double(null)是不合理的:
float64(0) 应该对 -> Double(0),
*float64(nil) -> Double(null),
如果go端要定义float64, 那么就要理解,java就不会出现null的情况,这是设计的一个部分,
就类似于protobuf中的 optional, 如果没有定义了optional,那就是0值,没有null值。

现在没有实现 Double(null) -> float64(nil), 但java定义Double/Integer 等也是硬需求。
这个部分和数据库数据到orm映射是一样的,如果数据库是 not null, 就可以用 int接数据,如果是可以是null, 就可以是
int 或者 sql.NullInt32等来接收。如何数据库是不是not null, 代码你非要写int,那也可以,只不过所有的null值都会变成0了。

@AlexStocks AlexStocks closed this Jan 29, 2022
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.

Java Double type covert to float64 panic when null value set.
3 participants