[Boost-bugs] [Boost C++ Libraries] #5210: JSON writer does not allow attributes and children in the same node

Subject: [Boost-bugs] [Boost C++ Libraries] #5210: JSON writer does not allow attributes and children in the same node
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-02-22 17:23:33


#5210: JSON writer does not allow attributes and children in the same node
-----------------------------------------------------------+----------------
 Reporter: Christian Ceelen <christian.ceelen@…> | Owner: cornedbee
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: property_tree
  Version: Boost 1.46.0 | Severity: Problem
 Keywords: |
-----------------------------------------------------------+----------------
 The JSON serialization of property_tree is currently restricts to
 instances of property_tree that do contain data attributes only in leaf
 node.

 {{{#!C++
     // Verify if ptree does not contain information that cannot be written
 to json
     template<class Ptree>
     bool verify_json(const Ptree &pt, int depth)
     {

         typedef typename Ptree::key_type::value_type Ch;
         typedef typename std::basic_string<Ch> Str;

         // Root ptree cannot have data
         if (depth == 0 && !pt.template get_value<Str>().empty())
             return false;

         // Ptree cannot have both children and data
         if (!pt.template get_value<Str>().empty() && !pt.empty())
             return false;

         // Check children
         typename Ptree::const_iterator it = pt.begin();
         for (; it != pt.end(); ++it)
             if (!verify_json(it->second, depth + 1))
                 return false;

         // Success
         return true;

     }
 }}}

 To me this is a random limitation.
 I removed it locally and tried to generate an instance with attributes and
 children:
 {{{
 {
     "Object":{
         "Name": "Object Name",
         "Child": {
             "Name": "Child Name"
         }
     }
 }
 }}}
 It works well.
 Why is this policy built into the json writer?
 Why is there no way to deactivate this policy?

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5210>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:05 UTC