RusticiSoftware/TinCan.NET

LanguageMap Add Problems

AnnabellBrocker opened this issue · 2 comments

I used the following code:

var verb = new Verb();
verb.id = new Uri("http://adlnet.gov/expapi/verbs/" + verbString);
verb.display = new LanguageMap();
verb.display.Add("Test", "Test2");
verb.display.Add("en-US", verbString);

Console.WriteLine(JsonConvert.SerializeObject(verb, Formatting.Indented));

the output is:
{
"id": "http://adlnet.gov/expapi/verbs/focussed",
"display": {}
}

As you can see, the Language Map seems to be initialized, but adding was not successful.

Debugging gives me this:

-- | -- | -- | --
◢ | verb | {TinCan.Verb} | TinCan.Verb
  | ◢ display | {TinCan.LanguageMap} | TinCan.LanguageMap
  | ◢ Non-Public members |   |  
  | ◢ map | Count = 2 | System.Collections.Generic.Dictionary<string, string>
  | ▶ [0] | {[Test, Test2]} | System.Collections.Generic.KeyValuePair<string, string>
  | ▶ [1] | {[en-US, focussed]} | System.Collections.Generic.KeyValuePair<string, string>
  | ▶ Raw View |   |  
  | ◢ id | {http://adlnet.gov/expapi/verbs/focussed} | System.Uri

In your debugger, we can see that display has two entries, so it doesn't look like adding the language map entries was unsuccessful. The issue is probably just with how the object is being serialized.

Most of the schema objects in this library inherit from JObject. This allows us access to a method ToJson(). (You can see examples of this method's use in our tests. For example, here: https://github.com/RusticiSoftware/TinCan.NET/blob/master/TinCanTests/VerbTest.cs#L48).

I personally haven't used JsonConvert in this library before, so I just want to make sure that the issue in on our side of things. Could you try serializing verb using ToJson() rather than JsonConvert? That method should fall into the the ToJObject overrides on our models, which is where we define how a class should be serialized.

If ToJson() doesn't work, then the problem is likely in LanguageMap.ToJObject, here: https://github.com/RusticiSoftware/TinCan.NET/blob/master/TinCan/LanguageMap.cs#L43 I'm not sure if anyone on our team would have the bandwidth to address a bug like this in the near future, but we're happy to review any PRs to fix the issue.

Okay yeah that is pretty interesting. When calling:

var verb = new Verb();
verb.id = new Uri("http://adlnet.gov/expapi/verbs/" + verbString);
verb.display = new LanguageMap();
verb.display.Add("Test", "Test2");
verb.display.Add("en-US", verbString);

Console.WriteLine(verb.ToJSON());

The output is:
{"id":"http://adlnet.gov/expapi/verbs/focussed","display":{"Test":"Test2","en-US":"focussed"}}

Okay great so it works, just using another JSON converter. Thanks :)