Fix double support: Parse actual numeric values instead of returning hardcoded 0/0.0#176
Merged
zhangruiyu merged 1 commit intofluttercandies:masterfrom Jun 30, 2025
Merged
Conversation
…hardcoded 0/0.0 - Fixed MapTypeAdapter.read() in GsonUtil.kt to parse and return actual numeric values - Previously all JSON numbers were replaced with hardcoded 0 (int) or 0.0 (double) - Now correctly parses integers to Long and doubles to Double with proper error handling - Added .intellijPlatform to .gitignore as recommended by build system Fixes double support functionality in JSON to Dart bean conversion.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The FlutterJsonBeanFactory plugin had broken double support because the
MapTypeAdapter.read()method inGsonUtil.ktwas returning hardcoded values (0for integers,0.0for doubles) instead of parsing the actual JSON numeric values.This meant that all numbers in JSON were being replaced with either
0or0.0, completely breaking the double support functionality.Solution
MapTypeAdapter.read()to parse and return actual numeric values usingdbNum.toLong()anddbNum.toDouble()0/0.0only when parsing fails.intellijPlatformto.gitignoreas recommended by the build systemChanges
GsonUtil.kt: Fixed number parsing logic inMapTypeAdapter.read()method (lines 117-137).gitignore: Added.intellijPlatformdirectoryTesting
The fix ensures that:
3.14159are preserved as3.14159(not0.0)42are preserved as42(not0)Before/After
Before: All JSON numbers →
0or0.0After: JSON numbers → actual parsed values with correct types
Root Cause
The original code was a placeholder implementation that correctly identified number types but forgot to actually parse and return the real values. This was likely an oversight during development where the type detection logic was implemented but the value parsing was left as hardcoded placeholders.