Github user brightchen commented on a diff in the pull request:
https://github.com/apache/incubator-apex-malhar/pull/103#discussion_r45141784
--- Diff:
library/src/main/java/com/datatorrent/lib/appdata/gpo/GPOUtils.java ---
@@ -178,33 +227,40 @@ public static void setFieldFromJSON(GPOMutable gpo,
Type type, String field, JSO
*/
public static void setFieldFromJSON(GPOMutable gpo, String field,
JSONObject jo)
{
- Type type = gpo.getFieldDescriptor().getType(field);
+ Object val = getFieldFromJSON(gpo.getFieldDescriptor(), field, jo);
+ gpo.setFieldGeneric(field, val);
+ }
- if(type == Type.BOOLEAN) {
- Boolean val;
+ /**
+ * This method gets the given field from the given {@link JSONObject}
and converts the field to an object
+ * of the type specified in the given {@link FieldsDescriptor}.
+ * @param fd The {@link FieldsDescriptor} describing the type of each
field.
+ * @param field The field to retrieve from the given {@link JSONObject}.
+ * @param jo The {@link JSONObject} to retrieve a field from.
+ * @return The value of the given field converted to an object of the
correct type.
+ */
+ public static Object getFieldFromJSON(FieldsDescriptor fd, String field,
JSONObject jo)
--- End diff --
maybe can combine the logic of integer numeric( byte, short, int ). such as
if(isIntegerNumeric(type))
{
int val = jo.getInt(field);
if( !insideRange(val, type) )
throw new IllegalArgumentException( "value {} out of range of type {}"
);
}
---
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 [email protected] or file a JIRA ticket
with INFRA.
---