Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Decoding array-like jsons
Decoding array-like jsons [message #1864807] Wed, 10 April 2024 11:19 Go to next message
Erwan Toux is currently offline Erwan TouxFriend
Messages: 6
Registered: March 2024
Junior Member
Hello everyone,

I am currently running some tests on JSON messages.
The messages I am trying to send/receive look something like this:

[
    some_integer,
    "some_string",
    "another_string",
    {
        keys : values
    }
]


The TTCN3 associated would be:

type union u_myJsonType := {
    integer int1,
    charstring char1,
    charstring char2,
    my_dict_type dict
} with { variant "JSON : as value"; }

type record of u_myJsonType myJsonType;


Using unions makes it possible to send such JSON messages (as an array, without the keys for each value).
However when decoding, as specified in the ETSI json guide , on paragraph 7.2.10, this gets decoded in two char1 strings, instead of one char1 and one char2.

Is there a way to bypass this (knowing that the json messages will always be sent in the same order) ?
If not, from what I could read it would mean having to write my own CoDec, do you have any good resources on how to get started ?
Also, I quite dislike having to use a record of union type, as I am no longer able to call attributes of the object (i.e. I can't do myJsonType.char2). Any input on this ?

Thank you,
Best regards,
Erwan
Re: Decoding array-like jsons [message #1864901 is a reply to message #1864807] Fri, 19 April 2024 13:16 Go to previous message
Adam Knapp is currently offline Adam KnappFriend
Messages: 54
Registered: November 2020
Member
Hi,

I have few comments on this.
Generally, a union contains different types as alternatives, and only one of the specified alternatives will ever be present in an actual union value. If you have alternatives of the same type, it is impossible to decide which alternative you would like to use in many cases, e.g. during decoding such a union. In this case the decoder will always select to fill the first charstring type as the input matches a charstring.
The other issue is that your message does not follow the JSON formatting. Therefore, the built-in JSON encoder/decoder will not be able to handle it properly. You can either write a custom decoder for your message, or you can try to use the built-in TEXT encoder (with proper attributes) to decode your message. The latter one is described in the reference guide: https://gitlab.eclipse.org/eclipse/titan/titan.core/-/blob/master/usrguide/referenceguide/4-ttcn3_language_extensions.adoc?ref_type=heads#user-content-text-encoder-and-decoder
Hope these helps!

[Updated on: Fri, 19 April 2024 13:17]

Report message to a moderator

Previous Topic:Templates with variable bindings support
Next Topic:Native ASN.1 PER for CHOICE
Goto Forum:
  


Current Time: Mon Oct 07 23:54:28 GMT 2024

Powered by FUDForum. Page generated in 0.04495 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top