Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » [Solved] Titan Json Decoder bug with enum and int(Include in the OneM2M project)
[Solved] Titan Json Decoder bug with enum and int [message #1767083] Fri, 30 June 2017 13:40 Go to next message
Kevin Thomas is currently offline Kevin ThomasFriend
Messages: 5
Registered: June 2017
Junior Member
Hi everyone,

I work on the OneM2M project and following to the documentation, we need to communicate some informations in Json (in a HTTP message). But even if we have a correct json structure, Titan doesn't decode it correctly.

Let me give an example :

We have a testcase where we try to create a ressource on a OneM2M Server (a Type 3 Ressource).

First, here is the log with a XML serialization.

MTC@linux-MS-7A71: dec_PrimitiveContentXML(): Stream before decoding: ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><m2m:container xmlns:m2m=\"http://ww w.onem2m.org/xml/protocols\" resourceName=\"cnt_196398224\">    <resourceType>3</resourceType>    <resourceID>/in-cse/cnt-196398224</resourceID>    <parentID>/in-cse</parentID>    <creationTime>20170630T111947</creationTime>    <lastModifiedTime>20170630T111947</lastModifiedTime>    <accessControlPolicyIDs>/in-cse/acp-761663881</accessControlPolicyIDs>    <expirationTime>20180630T111947</expirationTime>    <stateTag>0</stateTag>    <maxNrOfInstances>10</maxNrOfInstances>    <maxByteSize>10000</maxByteSize>    <maxInstanceAge>0</maxInstanceAge>    <currentNrOfInstances>0</currentNrOfInstances>    <currentByteSize>0</currentByteSize>    <oldest>/in-cse/in-name/cnt_196398224/ol</oldest>    <latest>/in-cse/in-name/cnt_196398224/la</latest></m2m:container>")
MTC@linux-MS-7A71: Warning: While XER-decoding type '@OneM2M_Types.PrimitiveContent': Alternative 'container': Unprocessed XML tag `oldest'
MTC@linux-MS-7A71: Warning: While XER-decoding type '@OneM2M_Types.PrimitiveContent': Alternative 'container': Unprocessed XML tag `latest'
MTC@linux-MS-7A71: dec_PrimitiveContentXML(): Decoded @OneM2M_Types.PrimitiveContent: { container := { resourceName := "cnt_196398224", resourceType := int3 (3), resourceID := "/in-cse/cnt-196398224", parentID := "/in-cse", creationTime := "20170630T111947", lastModifiedTime := "20170630T111947", labels := omit, accessControlPolicyIDs := { "/in-cse/acp-761663881" }, expirationTime := "20180630T111947", dynamicAuthorizationConsultationIDs := omit, announceTo := omit, announcedAttribute := omit, stateTag := 0, creator := omit, maxNrOfInstances := 10, maxByteSize := 10000, maxInstanceAge := 0, currentNrOfInstances := 0, currentByteSize := 0, locationID := omit, ontologyRef := omit, disableRetrieval := omit, choice := omit } }


As you can see we have in this message (in XML) :

<resourceType>3</resourceType>


And it becomes

resourceType := int3 (3)


It's correct and the testcase pass ! But in Json we have this :

MTC@linux-MS-7A71: dec_PrimitiveContentJSON(): Stream before decoding: ("{\"container\":{\"accessControlPolicyIDs\":[\"/in-cse/acp-761663881\"],\"creationTime\":\"20170630T111541\",\"currentByteSize\":0,\"currentNrOfInstances\":0,\"expirationTime\":\"20180630T111541\",\"lastModifiedTime\":\"20170630T111541\",\"latest\":\"/in-cse/in-name/cnt_508961637/la\",\"maxByteSize\":10000,\"maxInstanceAge\":0,\"maxNrOfInstances\":10,\"oldest\":\"/in-cse/in-name/cnt_508961637/ol\",\"parentID\":\"/in-cse\",\"resourceID\":\"/in-cse/cnt-508961637\",\"resourceName\":\"cnt_508961637\",\"resourceType\":3,\"stateTag\":0}}")
MTC@linux-MS-7A71: Warning: While JSON-decoding type '@OneM2M_Types.PrimitiveContent': Invalid field name 'latest'
MTC@linux-MS-7A71: Warning: While JSON-decoding type '@OneM2M_Types.PrimitiveContent': Invalid field name 'oldest'
MTC@linux-MS-7A71: Warning: While JSON-decoding type '@OneM2M_Types.PrimitiveContent': Invalid JSON token found while decoding field 'resourceType'
MTC@linux-MS-7A71: Warning: While JSON-decoding type '@OneM2M_Types.PrimitiveContent': Invalid JSON token found while decoding field 'container'
MTC@linux-MS-7A71: Warning: While JSON-decoding type '@OneM2M_Types.PrimitiveContent': Can not decode type '@OneM2M_Types.PrimitiveContent', because invalid or incomplete message was received
MTC@linux-MS-7A71: dec_PrimitiveContentJSON(): Decoded @OneM2M_Types.PrimitiveContent: { container := { resourceName := "cnt_508961637", resourceType := <unbound>, resourceID := "/in-cse/cnt-508961637", parentID := "/in-cse", creationTime := "20170630T111541", lastModifiedTime := "20170630T111541", labels := <unbound>, accessControlPolicyIDs := { "/in-cse/acp-761663881" }, expirationTime := "20180630T111541", dynamicAuthorizationConsultationIDs := <unbound>, announceTo := <unbound>, announcedAttribute := <unbound>, stateTag := <unbound>, creator := <unbound>, maxNrOfInstances := 10, maxByteSize := 10000, maxInstanceAge := 0, currentNrOfInstances := 0, currentByteSize := 0, locationID := <unbound>, ontologyRef := <unbound>, disableRetrieval := <unbound>, choice := <unbound> } }


As you can see we have this :

\"resourceType\":3


Which becomes :

resourceType := <unbound>


Because it hasn't the "int".

And if we force the "int" in order to have "int3", we obtain this log :

MTC@linux-MS-7A71: dec_PrimitiveContentJSON(): Stream before decoding: ("{\"container\":{\"accessControlPolicyIDs\":[\"/in-cse/acp-761663881\"],\"creationTime\":\"20170630T111742\",\"currentByteSize\":0,\"currentNrOfInstances\":0,\"expirationTime\":\"20180630T111742\",\"lastModifiedTime\":\"20170630T111742\",\"latest\":\"/in-cse/in-name/cnt_900407520/la\",\"maxByteSize\":10000,\"maxInstanceAge\":0,\"maxNrOfInstances\":10,\"oldest\":\"/in-cse/in-name/cnt_900407520/ol\",\"parentID\":\"/in-cse\",\"resourceID\":\"/in-cse/cnt-900407520\",\"resourceName\":\"cnt_900407520\",\"resourceType\":\"int3\",\"stateTag\":0}}")
MTC@linux-MS-7A71: Warning: While JSON-decoding type '@OneM2M_Types.PrimitiveContent': Invalid field name 'latest'
MTC@linux-MS-7A71: Warning: While JSON-decoding type '@OneM2M_Types.PrimitiveContent': Invalid field name 'oldest'
MTC@linux-MS-7A71: dec_PrimitiveContentJSON(): Decoded @OneM2M_Types.PrimitiveContent: { container := { resourceName := "cnt_900407520", resourceType := int3 (3), resourceID := "/in-cse/cnt-900407520", parentID := "/in-cse", creationTime := "20170630T111742", lastModifiedTime := "20170630T111742", labels := omit, accessControlPolicyIDs := { "/in-cse/acp-761663881" }, expirationTime := "20180630T111742", dynamicAuthorizationConsultationIDs := omit, announceTo := omit, announcedAttribute := omit, stateTag := 0, creator := omit, maxNrOfInstances := 10, maxByteSize := 10000, maxInstanceAge := 0, currentNrOfInstances := 0, currentByteSize := 0, locationID := omit, ontologyRef := omit, disableRetrieval := omit, choice := omit } }


As you can see this log have the correct Ressource Type, and the Testcase Pass.

Can you confirm that it's an error from Titan ?

If you require further information, please don't hesitate to contact me.

Best regards, Kevin.

[Updated on: Wed, 20 September 2017 08:19]

Report message to a moderator

Re: Titan Json Decoder bug with enum and int [message #1767214 is a reply to message #1767083] Mon, 03 July 2017 16:05 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 759
Registered: January 2015
Senior Member
Hi Kevin,

it is an error from Titan and it isn't. :)

Let me explain:

-in XML encoding , an enumerated value can be encoded as is , or as the associated integer value. By default, it is encoded as is, but using an
encoding variant "useNumber" , the encoding can be switched to the associated integer.
For instance:

type enumerated ProductColor { red(0), green(1), blue(2) }
with {
variant "useNumber"
}
type record NrProduct {
charstring name,
ProductColor color,
integer size
}
const NrProduct rval := {
name := "shirt",
color := red,
size := { sizeval := 10 }
}


rval will be encoded as:


<NrProduct>
<name>shirt</name>
<color>0</color>
<size>10</size>
</NrProduct>



-in JSON encoding the enumerated value is encoded as is, and the standard does not provision for an encoding modifier to encode as the associated integer

it is an omission in the standard, and, as we participated in writing the standard, it's at least partly our fault. :)

Let me discuss this with the team; we can probably fix this quickly by introducing an encoding variant as in XML and also submitting a change request to the standard.

I'll come back to you

Best regards
Elemer

Re: Titan Json Decoder bug with enum and int [message #1767361 is a reply to message #1767214] Wed, 05 July 2017 08:04 Go to previous messageGo to next message
Kevin Thomas is currently offline Kevin ThomasFriend
Messages: 5
Registered: June 2017
Junior Member
Hi Elemer,

Ok thanks for your help ! ;)

Best regards
Kevin.

[Updated on: Wed, 05 July 2017 08:05]

Report message to a moderator

Re: Titan Json Decoder bug with enum and int [message #1767593 is a reply to message #1767361] Fri, 07 July 2017 10:30 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 759
Registered: January 2015
Senior Member
Hi Kevin,

the above discussed encoding variant has been implemented.

You will need to build a Titan from source code if you want to use it,

see https://github.com/eclipse/titan.core README.linux for details.


You will also need to decorate your enum type declaration accordingly,

for example:

type enumerated Length { Short (0), Medium, Long(10) }
with {
  variant "JSON: as number"
}

type record of Length Lengths;
const Lengths c_len := { Short, Medium, Long };
// is encoded into: [ 0, 1, 10 ]


Naturally the decoder will also expect integer values instead of names.

We will also submit a change request to amend the standard.

Best regards

Elemer


Re: Titan Json Decoder bug with enum and int [message #1767601 is a reply to message #1767593] Fri, 07 July 2017 12:36 Go to previous message
Kevin Thomas is currently offline Kevin ThomasFriend
Messages: 5
Registered: June 2017
Junior Member
Hi Elemer,

Thanks for the correction i'm gonna update my TItan. :)

Best regards,

Kévin.
Previous Topic:Using the TLS_Handler part 2
Next Topic:Usage of ccache with TITAN
Goto Forum:
  


Current Time: Thu Jun 21 06:49:22 GMT 2018

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

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

Back to the top