JSON decoder bug/inconsistency
Submitted by G??bor Szalai
Link to original bug (#568645)
Description
In the following example the JSON decoder wrongly decode the union member: The JSON decoder ignores extra fields, but only if the extra fields either number or string.
module proba{
type union U1 { T1 field1, T2 field2, T3 field3 } with { variant "JSON: as value" }
type set T1{ integer i1 }
type set T2{ integer i1, integer i2 }
type set T3{ integer i1, record of integer i2 }
external function f_dec_U1(in octetstring stream, out U1 pdu) return integer with { extension "prototype(backtrack) decode(JSON)" }
control{ var octetstring stream; var U1 pdu_decoded; var integer result;
stream := char2oct("{ "i1":123}") result:=f_dec_U1(stream,pdu_decoded); log(stream) log(result) log(pdu_decoded)
stream := char2oct("{ "i1":123, "i2":456}") // decoded as { field1 := { i1 := 123 } } // the "i2":456 was ignored // should be { field2 := { i1 := 123 , i2 := 456} } result:=f_dec_U1(stream,pdu_decoded); log(stream) log(result) log(pdu_decoded)
stream := char2oct("{ "i1":123, "i2":[1,2,3]}") // decoded correctly result:=f_dec_U1(stream,pdu_decoded); log(stream) log(result) log(pdu_decoded)
}
} with { encode "JSON" }
Version: 7.1.0