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

Encoding numbers as json is buggy. #57

Open
xxgreg opened this issue Jan 21, 2015 · 0 comments
Open

Encoding numbers as json is buggy. #57

xxgreg opened this issue Jan 21, 2015 · 0 comments

Comments

@xxgreg
Copy link
Owner

xxgreg commented Jan 21, 2015

Typeconverter.dart Line: 163

Change to:

 if (value is num) {
      ...
      var n = value.toString();
      return "'$n'";
 }

Also note doc comment is wrong.

//FIXME can probably simplify this, as in postgresql json type must take
// map or array at top level, not string or number. (I think???)
String encodeValueToJson(value, {getConnectionName()}) {
if (value == null)
return "'null'";

if (value is Map || value is List)
  return encodeString(JSON.encode(value));

if (value is String)
  return encodeString('"$value"');

if (value is num) {
  // These are not valid JSON numbers, so encode them as strings.
  // TODO consider throwing an error instead.
  if (value.isNaN) return '"nan"';
  if (value == double.INFINITY) return '"infinity"';
  if (value == double.NEGATIVE_INFINITY) return '"-infinity"';
  return value.toString();
}

try {
  var map = value.toJson();
  return encodeString(JSON.encode(value));
} catch (e) {
  throw _error('Could not convert object to JSON. '
      'No toJson() method was implemented on the object.', getConnectionName);
}

}

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

No branches or pull requests

1 participant