Hi all! I’m trying to implement basic validation for dynamic data structures (those are coming from parsed JSON).
I want to have something like the following:
public static function getField<T>(
obj: Dynamic,
fieldName: String,
dflt: Null<T>,
context: Context): Null<T> {
var val = Reflect.field(obj, fieldName);
if (val == null) {
return dflt;
}
if (!Std.is(val, T)) {
throw new ValidationError('Unexpected value for ${context.getEntityInfo()}');
}
return val;
}
but Std.is(val, T)
is not working, because T is compilation type…
Can I achieve the same by some other means?