Remove usage of dart:json.
R=jmesserly@google.com, lrn@google.com, nweiz@google.com, rnystrom@google.com
Review URL: https://codereview.chromium.org//23596007
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26789 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/lib/src/credentials.dart b/lib/src/credentials.dart
index 5bbec16..13d3320 100644
--- a/lib/src/credentials.dart
+++ b/lib/src/credentials.dart
@@ -5,7 +5,7 @@
library credentials;
import 'dart:async';
-import 'dart:json' as JSON;
+import 'dart:convert';
import 'package:http/http.dart' as http;
@@ -80,7 +80,7 @@
var parsed;
try {
- parsed = JSON.parse(json);
+ parsed = JSON.decode(json);
} on FormatException catch (e) {
validate(false, 'invalid JSON');
}
@@ -125,7 +125,7 @@
/// Serializes a set of credentials to JSON. Nothing is guaranteed about the
/// output except that it's valid JSON and compatible with
/// [Credentials.toJson].
- String toJson() => JSON.stringify({
+ String toJson() => JSON.encode({
'accessToken': accessToken,
'refreshToken': refreshToken,
'tokenEndpoint': tokenEndpoint == null ? null : tokenEndpoint.toString(),
diff --git a/lib/src/handle_access_token_response.dart b/lib/src/handle_access_token_response.dart
index c14b8d1..129f259 100644
--- a/lib/src/handle_access_token_response.dart
+++ b/lib/src/handle_access_token_response.dart
@@ -5,7 +5,7 @@
library handle_access_token_response;
import 'dart:io';
-import 'dart:json' as JSON;
+import 'dart:convert';
import 'package:http/http.dart' as http;
@@ -39,7 +39,7 @@
var parameters;
try {
- parameters = JSON.parse(response.body);
+ parameters = JSON.decode(response.body);
} on FormatException catch (e) {
validate(false, 'invalid JSON');
}
@@ -108,7 +108,7 @@
var parameters;
try {
- parameters = JSON.parse(response.body);
+ parameters = JSON.decode(response.body);
} on FormatException catch (e) {
validate(false, 'invalid JSON');
}
diff --git a/test/authorization_code_grant_test.dart b/test/authorization_code_grant_test.dart
index 473fee1..85c54e7 100644
--- a/test/authorization_code_grant_test.dart
+++ b/test/authorization_code_grant_test.dart
@@ -5,7 +5,7 @@
library authorization_code_grant_test;
import 'dart:async';
-import 'dart:json' as JSON;
+import 'dart:convert';
import 'package:unittest/unittest.dart';
import 'package:http/http.dart' as http;
@@ -151,7 +151,7 @@
'client_secret': 'secret'
}));
- return new Future.value(new http.Response(JSON.stringify({
+ return new Future.value(new http.Response(JSON.encode({
'access_token': 'access token',
'token_type': 'bearer',
}), 200, headers: {'content-type': 'application/json'}));
@@ -195,7 +195,7 @@
'client_secret': 'secret'
}));
- return new Future.value(new http.Response(JSON.stringify({
+ return new Future.value(new http.Response(JSON.encode({
'access_token': 'access token',
'token_type': 'bearer',
}), 200, headers: {'content-type': 'application/json'}));
diff --git a/test/client_test.dart b/test/client_test.dart
index 922302d..56dd789 100644
--- a/test/client_test.dart
+++ b/test/client_test.dart
@@ -5,7 +5,7 @@
library client_test;
import 'dart:async';
-import 'dart:json' as JSON;
+import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:oauth2/oauth2.dart' as oauth2;
@@ -49,7 +49,7 @@
httpClient.expectRequest((request) {
expect(request.method, equals('POST'));
expect(request.url.toString(), equals(tokenEndpoint.toString()));
- return new Future.value(new http.Response(JSON.stringify({
+ return new Future.value(new http.Response(JSON.encode({
'access_token': 'new access token',
'token_type': 'bearer'
}), 200, headers: {'content-type': 'application/json'}));
@@ -99,7 +99,7 @@
httpClient.expectRequest((request) {
expect(request.method, equals('POST'));
expect(request.url.toString(), equals(tokenEndpoint.toString()));
- return new Future.value(new http.Response(JSON.stringify({
+ return new Future.value(new http.Response(JSON.encode({
'access_token': 'new access token',
'token_type': 'bearer'
}), 200, headers: {'content-type': 'application/json'}));
diff --git a/test/credentials_test.dart b/test/credentials_test.dart
index 6a873f2..f3e303b 100644
--- a/test/credentials_test.dart
+++ b/test/credentials_test.dart
@@ -5,7 +5,7 @@
library credentials_test;
import 'dart:async';
-import 'dart:json' as JSON;
+import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:oauth2/oauth2.dart' as oauth2;
@@ -74,7 +74,7 @@
"client_secret": "secret"
}));
- return new Future.value(new http.Response(JSON.stringify({
+ return new Future.value(new http.Response(JSON.encode({
'access_token': 'new access token',
'token_type': 'bearer',
'refresh_token': 'new refresh token'
@@ -104,7 +104,7 @@
"client_secret": "secret"
}));
- return new Future.value(new http.Response(JSON.stringify({
+ return new Future.value(new http.Response(JSON.encode({
'access_token': 'new access token',
'token_type': 'bearer'
}), 200, headers: {'content-type': 'application/json'}));
@@ -120,7 +120,7 @@
group("fromJson", () {
oauth2.Credentials fromMap(Map map) =>
- new oauth2.Credentials.fromJson(JSON.stringify(map));
+ new oauth2.Credentials.fromJson(JSON.encode(map));
test("should load the same credentials from toJson", () {
var expiration = new DateTime.now().subtract(new Duration(hours: 1));
diff --git a/test/handle_access_token_response_test.dart b/test/handle_access_token_response_test.dart
index 10e6f75..a99d8ea 100644
--- a/test/handle_access_token_response_test.dart
+++ b/test/handle_access_token_response_test.dart
@@ -4,7 +4,7 @@
library handle_access_token_response_test;
-import 'dart:json' as JSON;
+import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:oauth2/oauth2.dart' as oauth2;
@@ -70,28 +70,28 @@
});
test('with a non-string error_description causes a FormatException', () {
- expect(() => handleError(body: JSON.stringify({
+ expect(() => handleError(body: JSON.encode({
"error": "invalid_request",
"error_description": 12
})), throwsFormatException);
});
test('with a non-string error_uri causes a FormatException', () {
- expect(() => handleError(body: JSON.stringify({
+ expect(() => handleError(body: JSON.encode({
"error": "invalid_request",
"error_uri": 12
})), throwsFormatException);
});
test('with a string error_description causes a AuthorizationException', () {
- expect(() => handleError(body: JSON.stringify({
+ expect(() => handleError(body: JSON.encode({
"error": "invalid_request",
"error_description": "description"
})), throwsAuthorizationException);
});
test('with a string error_uri causes a AuthorizationException', () {
- expect(() => handleError(body: JSON.stringify({
+ expect(() => handleError(body: JSON.encode({
"error": "invalid_request",
"error_uri": "http://example.com/error"
})), throwsAuthorizationException);
@@ -106,7 +106,7 @@
expiresIn,
refreshToken,
scope}) {
- return handle(new http.Response(JSON.stringify({
+ return handle(new http.Response(JSON.encode({
'access_token': accessToken,
'token_type': tokenType,
'expires_in': expiresIn,