Skip to content
Discussion options

You must be logged in to vote

Looks like I found a workaround, we need to return an ObjectInstance for the toJSON method.

public sealed class PersonWithToJsonJsValue(Jint.Engine engine)
{
    public string name { get; set; }
    public int age { get; set; }
    public ObjectInstance toJSON(JsValue v)
    {
        ObjectInstance obj = engine.Intrinsics.Object.Construct([]);
        obj.Set("name", name);
        obj.Set("age", age);
        return obj;
    }
}

[TestMethod]
public void TestJsonStringifyWithObjectWithToJsonReturningJsValue()
{
    Jint.Engine engine = new();
    PersonWithToJsonJsValue person = new(engine) { name = "John", age = 30 };
    engine.SetValue("person", person);
    string result = engine.Ev…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kxs-rgamezdiaz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant