-
-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JObjectArray Stringify error #1005
Comments
This test can be run and passed,
but not work in OrchardCore ,Even though I commented out these lines of code IEnumerable<dynamic> queryResults;
using (connection)
{
await connection.OpenAsync();
using (var transaction = connection.BeginTransaction(_session.Store.Configuration.IsolationLevel))
{
queryResults = await connection.QueryAsync(rawQuery, parameters, transaction);
}
}
/* var results = new List<JObject>();
foreach (var document in queryResults)
{
results.Add(JObject.FromObject(document));
}*/
sqlQueryResults.Items = queryResults;
return sqlQueryResults; |
Part of the reason I've found is that if the input object is of type List, it will fail, but if the ToArray() method is called before Jint is passed in, the program will work fine Here is my test code: //https://github.com/OrchardCMS/OrchardCore/issues/10648
[Fact]
public void EngineShouldStringifyAnJObjectListWithValuesCorrectly()
{
var engine = new Engine();
List<dynamic> queryResults = new List<dynamic>();
queryResults.Add(new { Text = "Text1", Value = 1 });
queryResults.Add(new { Text = "Text2", Value = 2 });
engine.SetValue("testSubject", queryResults.Select(x => JObject.FromObject(x)));
var fromEngine = engine.Evaluate("return JSON.stringify(testSubject);");
var result = fromEngine.ToString();
Assert.Equal(result, "[{\"Text\":\"Text1\",\"Value\":1},{\"Text\":\"Text2\",\"Value\":2}]");
}
[Fact]
public void EngineShouldStringifyAnJObjectArrayWithValuesCorrectly()
{
//https://github.com/OrchardCMS/OrchardCore/issues/10648
var engine = new Engine();
List<dynamic> queryResults = new List<dynamic>();
queryResults.Add(new { Text = "Text1", Value = 1 });
queryResults.Add(new { Text = "Text2", Value = 2 });
engine.SetValue("testSubject", queryResults.ToArray());
var fromEngine2 = engine.Evaluate("return JSON.stringify(testSubject);");
var result2 = fromEngine2.ToString();
Assert.Equal(result2, "[{\"Text\":\"Text1\",\"Value\":1},{\"Text\":\"Text2\",\"Value\":2}]");
}
[Fact]
public void EngineShouldStringifyDynamicObjectListWithValuesCorrectly()
{
var engine = new Engine();
var source = new dynamic[] { new { Text = "Text1", Value = 1 }, new { Text = "Text2", Value = 2 } };
engine.SetValue("testSubject", source.ToList());
var fromEngine = engine.Evaluate("return JSON.stringify(testSubject);");
var result = fromEngine.ToString();
Assert.Equal(result, "[{\"Text\":\"Text1\",\"Value\":1},{\"Text\":\"Text2\",\"Value\":2}]");
}
[Fact]
public void EngineShouldStringifyDynamicObjectArrayWithValuesCorrectly()
{
var engine = new Engine();
var source = new dynamic[] { new { Text = "Text1", Value = 1 }, new { Text = "Text2", Value = 2 } };
engine.SetValue("testSubject", source.AsEnumerable());
var fromEngine = engine.Evaluate("return JSON.stringify(testSubject);");
var result = fromEngine.ToString();
Assert.Equal(result, "[{\"Text\":\"Text1\",\"Value\":1},{\"Text\":\"Text2\",\"Value\":2}]");
} |
I can certainly fix the List stringify problem, but enumerators are a different thing ( |
@hyzx86 we can help with the concrete list but the enumerator is a bit hard like stated. I see you've created a PR to address this on Orchard's side so maybe not something we can improve further. |
Ok, GOT it. Thank you |
Hi @lahma , have you update the nuget version? |
@hyzx86 You can use the MyGet feed for each main release, described in the main README. |
Hi @lahma ,That test will be faild [Fact]
public void EngineShouldStringifyJObjectFromObjectListWithValuesCorrectly()
{
var engine = new Engine();
var source = new dynamic[] { new { Text = "Text1", Value = 1 }, new { Text = "Text2", Value = 2 } };
engine.SetValue("testSubject", source.Select(x => JObject.FromObject(x)).ToList());
var fromEngine = engine.Evaluate("return JSON.stringify(testSubject);");
var result = fromEngine.ToString();
Assert.Equal(result, "[{\"Text\":\"Text1\",\"Value\":1},{\"Text\":\"Text2\",\"Value\":2}]");
} |
OrchardCMS/OrchardCore#10648
out put :
The text was updated successfully, but these errors were encountered: