diff --git a/JSONObject.cs b/JSONObject.cs index ddbd796..f0a3c6c 100644 --- a/JSONObject.cs +++ b/JSONObject.cs @@ -3,8 +3,9 @@ using System.Text; using System.Collections.Generic; using System.Reflection; using System.Linq; -using ln.types.btree; using System.Security.Cryptography; +using ln.types.btree; +using ln.json.mapping; namespace ln.json { @@ -28,17 +29,27 @@ namespace ln.json set => values[property] = value; } - public JSONObject Add(string propertyName,JSONValue value) + public JSONObject Add(string propertyName, JSONValue value) { values[propertyName] = value; return this; } + public JSONObject Add(string propertyName, object value) + { + values[propertyName] = JSONMapper.DefaultMapper.ToJson(value); + return this; + } public bool ContainsKey(string key) { return values.ContainsKey(key); } + public T ToObject() + { + return JSONMapper.DefaultMapper.FromJson(this); + } + public override string ToString() { StringBuilder sb = new StringBuilder(); @@ -63,5 +74,12 @@ namespace ln.json return sb.ToString(); } + public static JSONObject From(object value) + { + return (JSONObject)JSONMapper.DefaultMapper.ToJson(value); + } + } + + }