1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/base/serializers.h"
7 #include "base/json/json_string_value_serializer.h"
8 #include "base/logging.h"
10 namespace chromecast
{
12 scoped_ptr
<base::Value
> DeserializeFromJson(const std::string
& text
) {
13 JSONStringValueDeserializer
deserializer(text
);
16 std::string error_msg
;
17 scoped_ptr
<base::Value
> value(
18 deserializer
.Deserialize(&error_code
, &error_msg
));
19 DLOG_IF(ERROR
, !value
) << "JSON error " << error_code
<< ":" << error_msg
;
21 // Value will hold the nullptr in case of an error.
25 scoped_ptr
<std::string
> SerializeToJson(const base::Value
& value
) {
26 scoped_ptr
<std::string
> json_str(new std::string());
27 JSONStringValueSerializer
serializer(json_str
.get());
28 if (!serializer
.Serialize(value
))
29 json_str
.reset(nullptr);
30 return json_str
.Pass();
33 } // namespace chromecast