diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index b8119f5..8d0e7d2 100644
a
|
b
|
from StringIO import StringIO
|
8 | 8 | |
9 | 9 | from django.core.serializers.python import Serializer as PythonSerializer |
10 | 10 | from django.core.serializers.python import Deserializer as PythonDeserializer |
| 11 | from django.core.serializers import base |
11 | 12 | from django.utils import datetime_safe |
12 | 13 | from django.utils import simplejson |
13 | 14 | |
… |
… |
class Serializer(PythonSerializer):
|
24 | 25 | if callable(getattr(self.stream, 'getvalue', None)): |
25 | 26 | return self.stream.getvalue() |
26 | 27 | |
| 28 | |
27 | 29 | def Deserializer(stream_or_string, **options): |
28 | 30 | """ |
29 | 31 | Deserialize a stream or string of JSON data. |
… |
… |
def Deserializer(stream_or_string, **options):
|
32 | 34 | stream = StringIO(stream_or_string) |
33 | 35 | else: |
34 | 36 | stream = stream_or_string |
35 | | for obj in PythonDeserializer(simplejson.load(stream), **options): |
36 | | yield obj |
| 37 | try: |
| 38 | for obj in PythonDeserializer(simplejson.load(stream), **options): |
| 39 | yield obj |
| 40 | except ValueError, e: |
| 41 | # Map to deserializer error |
| 42 | raise base.DeserializationError(e.args) |
| 43 | |
37 | 44 | |
38 | 45 | class DjangoJSONEncoder(simplejson.JSONEncoder): |
39 | 46 | """ |
diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
index 97b2a79..24a149b 100644
a
|
b
|
class SerializerTests(TestCase):
|
374 | 374 | with self.assertRaises(SerializerDoesNotExist): |
375 | 375 | serializers.get_deserializer("nonsense") |
376 | 376 | |
| 377 | def test_json_deserializer_exception(self): |
| 378 | from django.core.serializers import base |
| 379 | with self.assertRaises(base.DeserializationError): |
| 380 | data = serializers.deserialize("json", """[{"pk":1}""") |
| 381 | for obj in data: |
| 382 | pass |
| 383 | |
377 | 384 | def serializerTest(format, self): |
378 | 385 | |
379 | 386 | # Create all the objects defined in the test data |