Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Issue 10440101: ABANDONED: Update base::JSONValueConverter to support custom actions. (Closed)

Created:
8 years, 6 months ago by Daniel Erat
Modified:
8 years, 6 months ago
Reviewers:
Jun Mukai, awong
CC:
chromium-reviews, erikwright (departed), brettw-cc_chromium.org
Visibility:
Public.

Description

Update base::JSONValueConverter to support custom actions. The existing RegisterCustomField() method requires that the caller provide a conversion function and specify the location where the resulting value should be saved. This change adds RegisterCustomAction() and RegisterRepeatedCustomAction(), which can be used to add handlers that perform arbitrary actions. For example, this is useful if you have JSON like this: {"link": [ {"type": "email", "href": "me@example.org"}, {"type": "home", "href": "http://www.example.org"} ]} and you want to store it in a class like: struct Links { std::string email_href; std::string home_href; }; RegisterRepeatedCustomAction() can be used to register a function that that receives a DictionaryValue for to each element in the "link" list and saves its "href" field to the appropriate member in Links depending on the value of the "type" field. BUG=128805 TEST=added

Patch Set 1 #

Total comments: 1

Patch Set 2 : rename constants in test #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+234 lines, -42 lines) Patch
M base/json/json_value_converter.h View 19 chunks +115 lines, -42 lines 0 comments Download
M base/json/json_value_converter_unittest.cc View 1 4 chunks +119 lines, -0 lines 1 comment Download

Messages

Total messages: 2 (0 generated)
Daniel Erat
https://chromiumcodereview.appspot.com/10440101/diff/1/base/json/json_value_converter.h File base/json/json_value_converter.h (right): https://chromiumcodereview.appspot.com/10440101/diff/1/base/json/json_value_converter.h#newcode105 base/json/json_value_converter.h:105: class FieldHandlerBase { I renamed this since it's not ...
8 years, 6 months ago (2012-05-30 23:18:14 UTC) #1
Jun Mukai
8 years, 6 months ago (2012-05-30 23:51:10 UTC) #2
lgtm

https://chromiumcodereview.appspot.com/10440101/diff/2001/base/json/json_valu...
File base/json/json_value_converter_unittest.cc (right):

https://chromiumcodereview.appspot.com/10440101/diff/2001/base/json/json_valu...
base/json/json_value_converter_unittest.cc:34: std::string home_href;
Can you define another struct for custom actions?
I feel the "SimpleMessage" got a bit complicated now.

Powered by Google App Engine
This is Rietveld 408576698