Skip to content

Commit 6839a46

Browse files
committed
Fixing overly aggressive removal of json::details::_Value::_copy_value API.
1 parent 874837e commit 6839a46

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Release/include/cpprest/json.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,8 @@ namespace json
14181418
class _Value
14191419
{
14201420
public:
1421+
virtual std::unique_ptr<_Value> _copy_value() = 0;
1422+
14211423
virtual bool has_field(const utility::string_t &) const { return false; }
14221424
virtual value get_field(const utility::string_t &) const { throw json_exception(_XPLATSTR("not an object")); }
14231425
virtual value get_element(array::size_type) const { throw json_exception(_XPLATSTR("not an array")); }
@@ -1487,6 +1489,10 @@ namespace json
14871489
class _Null : public _Value
14881490
{
14891491
public:
1492+
virtual std::unique_ptr<_Value> _copy_value()
1493+
{
1494+
return utility::details::make_unique<_Null>();
1495+
}
14901496
virtual json::value::value_type type() const { return json::value::Null; }
14911497
};
14921498

@@ -1499,6 +1505,11 @@ namespace json
14991505
_Number(int64_t value) : m_number(value) { }
15001506
_Number(uint64_t value) : m_number(value) { }
15011507

1508+
virtual std::unique_ptr<_Value> _copy_value()
1509+
{
1510+
return utility::details::make_unique<_Number>(*this);
1511+
}
1512+
15021513
virtual json::value::value_type type() const { return json::value::Number; }
15031514

15041515
virtual bool is_integer() const { return m_number.is_integral(); }
@@ -1532,6 +1543,11 @@ namespace json
15321543
public:
15331544
_Boolean(bool value) : m_value(value) { }
15341545

1546+
virtual std::unique_ptr<_Value> _copy_value()
1547+
{
1548+
return utility::details::make_unique<_Boolean>(*this);
1549+
}
1550+
15351551
virtual json::value::value_type type() const { return json::value::Boolean; }
15361552

15371553
virtual bool as_bool() const { return m_value; }
@@ -1577,6 +1593,11 @@ namespace json
15771593
{ }
15781594
#endif
15791595

1596+
virtual std::unique_ptr<_Value> _copy_value()
1597+
{
1598+
return utility::details::make_unique<_String>(*this);
1599+
}
1600+
15801601
virtual json::value::value_type type() const { return json::value::String; }
15811602

15821603
virtual const utility::string_t & as_string() const;
@@ -1643,6 +1664,11 @@ namespace json
16431664
_Object(bool keep_order) : m_object(keep_order) { }
16441665
_Object(object::storage_type fields, bool keep_order) : m_object(std::move(fields), keep_order) { }
16451666

1667+
virtual std::unique_ptr<_Value> _copy_value()
1668+
{
1669+
return utility::details::make_unique<_Object>(*this);
1670+
}
1671+
16461672
virtual json::object& as_object() { return m_object; }
16471673

16481674
virtual const json::object& as_object() const { return m_object; }
@@ -1749,6 +1775,11 @@ namespace json
17491775
_Array(array::size_type size) : m_array(size) {}
17501776
_Array(array::storage_type elements) : m_array(std::move(elements)) { }
17511777

1778+
virtual std::unique_ptr<_Value> _copy_value()
1779+
{
1780+
return utility::details::make_unique<_Array>(*this);
1781+
}
1782+
17521783
virtual json::value::value_type type() const { return json::value::Array; }
17531784

17541785
virtual json::array& as_array() { return m_array; }

Release/src/json/json.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ m_value(utility::details::make_unique<web::json::details::_String>(utility::stri
123123
{ }
124124

125125
web::json::value::value(const value &other) :
126-
m_value(other.m_value.get())
126+
m_value(other.m_value->_copy_value())
127127
#ifdef ENABLE_JSON_VALUE_VISUALIZER
128128
,m_kind(other.m_kind)
129129
#endif
@@ -133,7 +133,7 @@ web::json::value &web::json::value::operator=(const value &other)
133133
{
134134
if(this != &other)
135135
{
136-
m_value = std::unique_ptr<details::_Value>(other.m_value.get());
136+
m_value = std::unique_ptr<details::_Value>(other.m_value->_copy_value());
137137
#ifdef ENABLE_JSON_VALUE_VISUALIZER
138138
m_kind = other.m_kind;
139139
#endif

0 commit comments

Comments
 (0)