Skip to content

Commit

Permalink
KAZOO-2394: continue typecasting intergers and numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anderson committed Jan 27, 2015
1 parent f6121a9 commit e2eaac3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions deps/jesse-1.1.5/src/jesse_validator_draft3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ check_type(Value, Type, State) ->

%% @private
is_type_valid(Value, ?STRING, _State) -> is_binary(Value);
is_type_valid(Value, ?NUMBER, _State) -> is_number(Value);
is_type_valid(Value, ?INTEGER, _State) -> is_integer(Value);
is_type_valid(Value, ?BOOLEAN, _State) -> is_boolean(Value);
is_type_valid(Value, ?NUMBER, _State) -> try_converting(Value, fun wh_util:to_number/1, fun erlang:is_number/1);
is_type_valid(Value, ?INTEGER, _State) -> try_converting(Value, fun wh_util:to_integer/1, fun erlang:is_integer/1);
is_type_valid(Value, ?BOOLEAN, _State) -> wh_util:is_boolean(Value);
is_type_valid(Value, ?OBJECT, _State) -> jesse_lib:is_json_object(Value);
is_type_valid(Value, ?ARRAY, _State) -> jesse_lib:is_array(Value);
is_type_valid(Value, ?NULL, _State) -> jesse_lib:is_null(Value);
Expand All @@ -286,6 +286,15 @@ is_type_valid(Value, UnionType, State) ->
false -> true
end.

try_converting(Value, CastFun, ValidatorFun) ->
try CastFun(Value) of
Casted ->
ValidatorFun(Casted)
catch
_E:_R ->
'false'
end.

%% @private
check_union_type(Value, UnionType, State) ->
lists:any( fun(Type) ->
Expand Down

0 comments on commit e2eaac3

Please sign in to comment.