| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library polymer.deserialize; | 5 library polymer.deserialize; |
| 6 | 6 |
| 7 import 'dart:convert' show JSON; | 7 import 'dart:convert' show JSON; |
| 8 import 'dart:mirrors' show reflect, TypeMirror; | 8 import 'dart:mirrors' show TypeMirror; |
| 9 | 9 |
| 10 final _typeHandlers = () { | 10 final _typeHandlers = () { |
| 11 // TODO(jmesserly): switch to map and symbol literal form when supported. | 11 // TODO(jmesserly): switch to map and symbol literal form when supported. |
| 12 var m = new Map(); | 12 var m = new Map(); |
| 13 m[#dart.core.String] = (x, _) => x; | 13 m[#dart.core.String] = (x, _) => x; |
| 14 m[#dart.core.Null] = (x, _) => x; | 14 m[#dart.core.Null] = (x, _) => x; |
| 15 m[#dart.core.DateTime] = (x, _) { | 15 m[#dart.core.DateTime] = (x, _) { |
| 16 // TODO(jmesserly): shouldn't need to try-catch here | 16 // TODO(jmesserly): shouldn't need to try-catch here |
| 17 // See: https://code.google.com/p/dart/issues/detail?id=1878 | 17 // See: https://code.google.com/p/dart/issues/detail?id=1878 |
| 18 try { | 18 try { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 42 // quotes altogether, parse will fail. | 42 // quotes altogether, parse will fail. |
| 43 return JSON.decode(value.replaceAll("'", '"')); | 43 return JSON.decode(value.replaceAll("'", '"')); |
| 44 | 44 |
| 45 // TODO(jmesserly): deserialized JSON is not assignable to most objects in | 45 // TODO(jmesserly): deserialized JSON is not assignable to most objects in |
| 46 // Dart. We should attempt to convert it appropriately. | 46 // Dart. We should attempt to convert it appropriately. |
| 47 } catch(e) { | 47 } catch(e) { |
| 48 // The object isn't valid JSON, return the raw value | 48 // The object isn't valid JSON, return the raw value |
| 49 return value; | 49 return value; |
| 50 } | 50 } |
| 51 } | 51 } |
| OLD | NEW |