Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
Expand Down
16 changes: 6 additions & 10 deletions source/dotnet/Library/AdaptiveCards/AdaptiveInlinesConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var array = JArray.Load(reader);
List<object> list = array.ToObject<List<object>>();
List<AdaptiveInline> arrayList = new List<AdaptiveInline>();
var serializerSettigns = new JsonSerializerSettings
{
ContractResolver = new WarningLoggingContractResolver(new AdaptiveCardParseResult(), ParseContext),
Converters = { new StrictIntConverter() }
Copy link

@shalinijoshi19 shalinijoshi19 Nov 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StrictIntConverter [](start = 35, length = 18)

Question: Why this? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have particular reason for using the converter. I'm following the usage shown in AdaptiveCard.cs LN239-242. I couldn't find reasons to differ.


In reply to: 341414800 [](ancestors = 341414800)

};

// We only support text runs for now, which can be specified as either a string or an object
foreach (object obj in list)
Expand All @@ -40,16 +45,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
throw new AdaptiveSerializationException($"Property 'type' must be '{AdaptiveTextRun.TypeName}'");
}

if(ParseContext == null) {
ParseContext = new ParseContext();
}

var adaptiveInline = JsonConvert.DeserializeObject<AdaptiveTextRun>(jobj.ToString(), new JsonSerializerSettings
{
ContractResolver = new WarningLoggingContractResolver(new AdaptiveCardParseResult(), ParseContext),
Converters = { new StrictIntConverter() }
});
arrayList.Add(adaptiveInline);
arrayList.Add(JsonConvert.DeserializeObject<AdaptiveTextRun>(jobj.ToString(), serializerSettigns));
}
}
return arrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdaptiveCards
{
/// <summary>
/// JsonConverters that deserialize to Adpative Elements and require
/// ParseContext must inherit this Class
/// ParseContext provides id generation, id collision detections, and other useful
/// services during deserialization
/// </summary>
public abstract class AdaptiveTypedBaseElementConverter : JsonConverter
{
protected ParseContext parseContext;
public ParseContext ParseContext
{
get => parseContext;
set
{
parseContext = value;
}
}
public ParseContext ParseContext { get; set; } = new ParseContext();
}
}
12 changes: 2 additions & 10 deletions source/dotnet/Library/AdaptiveCards/ParseContext.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -25,16 +27,6 @@ public void PushElement(string idJsonProperty, AdaptiveInternalID internalId)
idStack.Push(new Tuple<string, AdaptiveInternalID, bool>(idJsonProperty, internalId, AdaptiveFallbackConverter.IsInFallback));
}

public AdaptiveInternalID PeekElement()
{
if (idStack.Count == 0)
{
// internal id in dot net needs to be revisited tracked via issue 3386
return new AdaptiveInternalID();
}
return idStack.Peek().Item2;
}

// Pop the last id off our stack and perform validation
public void PopElement()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ public void TestParsingRichTextBlockWithInvalidInlineType()

StringAssert.Contains(ex.Message, "Property 'type' must be 'TextRun'");
}

void RenderCardTask(string payload)
{
AdaptiveCardParseResult parseResult = AdaptiveCard.FromJson(payload);
Expand Down Expand Up @@ -1392,7 +1393,7 @@ public void TestConcurrentParsing()
{
// it's perfectly fine card. if there is exception, it is due to concurreny
// as it's the only variable.
Assert.Fail();
Assert.Fail("Unexpected failure parsing a valid AdaptiveCard");
}
}
}
Expand Down