apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilooner <...@git.apache.org>
Subject [GitHub] incubator-apex-malhar pull request: - MLHR-1908 Added helper metho...
Date Tue, 17 Nov 2015 20:35:58 GMT
Github user ilooner commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/103#discussion_r45116680
  
    --- Diff: library/src/main/java/com/datatorrent/lib/appdata/gpo/GPOUtils.java ---
    @@ -123,6 +123,54 @@ public static GPOMutable deserialize(FieldsDescriptor fieldsDescriptor,
       }
     
       /**
    +   * This method deserializes the fields in the given {@link FieldsDescriptor} into a
map.
    +   * @param fieldsDescriptor The {@link FieldsDescriptor} to fetch fields from.
    +   * @param dpou The {@link JSONObject} which contains the fields whose values need to
be fetched.
    +   * @return A {@link Map} whose keys are field names, and whose values are possible
values for those fields.
    +   */
    +  public static Map<String, Set<Object>> deserializeToMap(FieldsDescriptor
fieldsDescriptor,
    +                                                          JSONObject dpou)
    +  {
    +    Map<String, Set<Object>> keyToValues = Maps.newHashMap();
    +
    +    for (String key : fieldsDescriptor.getFields().getFields()) {
    +      if (!dpou.has(key)) {
    +        throw new IllegalArgumentException("The given key " + key + " is not contained
in the given JSON");
    +      }
    +
    +      Type type = fieldsDescriptor.getType(key);
    +      Set<Object> keyValues = Sets.newHashSet();
    +      keyToValues.put(key, keyValues);
    +
    +      Object keyValue;
    +
    +      try {
    +        keyValue = dpou.get(key);
    +      } catch (JSONException ex) {
    --- End diff --
    
    This is a convenience method for handling JSON. it is not convenient to do exception handling
every time this method is called. It also doesn't enable you to do anything useful.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message