Skip to content

Comments

Fix double support: Parse actual numeric values instead of returning hardcoded 0/0.0#176

Merged
zhangruiyu merged 1 commit intofluttercandies:masterfrom
ikku47:fix-double-support
Jun 30, 2025
Merged

Fix double support: Parse actual numeric values instead of returning hardcoded 0/0.0#176
zhangruiyu merged 1 commit intofluttercandies:masterfrom
ikku47:fix-double-support

Conversation

@ikku47
Copy link

@ikku47 ikku47 commented Jun 30, 2025

Problem

The FlutterJsonBeanFactory plugin had broken double support because the MapTypeAdapter.read() method in GsonUtil.kt was returning hardcoded values (0 for integers, 0.0 for doubles) instead of parsing the actual JSON numeric values.

This meant that all numbers in JSON were being replaced with either 0 or 0.0, completely breaking the double support functionality.

Solution

  • Fixed MapTypeAdapter.read() to parse and return actual numeric values using dbNum.toLong() and dbNum.toDouble()
  • Maintained proper error handling with fallback to 0/0.0 only when parsing fails
  • Added .intellijPlatform to .gitignore as recommended by the build system

Changes

  • GsonUtil.kt: Fixed number parsing logic in MapTypeAdapter.read() method (lines 117-137)
  • .gitignore: Added .intellijPlatform directory

Testing

The fix ensures that:

  • ✅ JSON numbers like 3.14159 are preserved as 3.14159 (not 0.0)
  • ✅ JSON integers like 42 are preserved as 42 (not 0)
  • ✅ Type detection continues to work correctly
  • ✅ Error handling is maintained

Before/After

Before: All JSON numbers → 0 or 0.0
After: 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.

…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.
@ikku47 ikku47 requested a review from zhangruiyu as a code owner June 30, 2025 08:29
@zhangruiyu zhangruiyu merged commit 3a770d7 into fluttercandies:master Jun 30, 2025
3 of 4 checks passed
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