diff --git a/compiler2/Type.cc b/compiler2/Type.cc index e466afb327c2970f4da74345d11ca9e5bbb7ee8f..832c0602918974808731062a4067b55a4072fa05 100644 --- a/compiler2/Type.cc +++ b/compiler2/Type.cc @@ -3252,19 +3252,13 @@ namespace Common { case T_OPENTYPE: for (size_t i = 0; i < get_nof_comps(); ++i) { Type* field_type = get_comp_byIndex(i)->get_type(); - if (field_type->has_encoding(coding, NULL) || - field_type->get_type_w_coding_table() == NULL) { - field_type->get_type_refd_last()->set_gen_coder_functions(coding); - } + field_type->get_type_refd_last()->set_gen_coder_functions(coding); } break; case T_SEQOF: case T_SETOF: case T_ARRAY: - if (get_ofType()->has_encoding(coding, NULL) || - get_ofType()->get_type_w_coding_table() == NULL) { - get_ofType()->get_type_refd_last()->set_gen_coder_functions(coding); - } + get_ofType()->get_type_refd_last()->set_gen_coder_functions(coding); break; default: break; diff --git a/regression_test/multipleEncodings/Testcases.ttcn b/regression_test/multipleEncodings/Testcases.ttcn index a9fca73c7810a97e31dc55a7d1ec7e256d3f9f10..260a7dc05f8c3fc7eabb8e2afc554052fc1d9288 100644 --- a/regression_test/multipleEncodings/Testcases.ttcn +++ b/regression_test/multipleEncodings/Testcases.ttcn @@ -457,6 +457,25 @@ testcase tc_asn_setencode_negtest() runs on CT { } } +// Encoding and decoding a type, that has JSON encoding set on the top level, but its element type +// and the element type's fields don't have JSON encoding. The entire structure must be encodable +// with JSON. +testcase tc_ttcn_codec_switch() runs on CT { + var RecOf x := { { f1 := val1 }, { f1 := val2 } }; + var universal charstring exp := "[{\"f1\":\"val1\"},{\"f1\":\"val2\"}]"; + var universal charstring enc := encvalue_unichar(x, "UTF-8"); + if (exp != enc) { + setverdict(fail, "Encvalue_unichar test failed. Expected: ", exp, ", got: ", enc); + } + + var RecOf dec; + var integer res := decvalue_unichar(enc, dec); + if (x != dec) { + setverdict(fail, "Decvalue test failed. Expected: ", x, ", got: ", dec); + } + setverdict(pass); +} + control { execute(tc_ttcn_encvalue()); execute(tc_ttcn_encvalue_negtest()); @@ -475,6 +494,7 @@ control { execute(tc_asn_setencode_json()); execute(tc_asn_setencode_per()); execute(tc_asn_setencode_negtest()); + execute(tc_ttcn_codec_switch()); } } diff --git a/regression_test/multipleEncodings/TtcnTypes.ttcn b/regression_test/multipleEncodings/TtcnTypes.ttcn index 22560d2171b6cc21a5e503903915793670103409..cfee27c6ccc1c1e0b397c3c07dcbab10d24011fd 100644 --- a/regression_test/multipleEncodings/TtcnTypes.ttcn +++ b/regression_test/multipleEncodings/TtcnTypes.ttcn @@ -51,6 +51,11 @@ with { variant "JSON: as value"; } +type record of R1 RecOf +with { + encode "JSON"; +} + type record Msg { bitstring data }