anonymous object java code example

Example 1: ihttpactionresult to object c#

[TestMethod]
public void TestGet()
{
    IHttpActionResult actionResult = controller.Get();
    var contentResult = actionResult as OkNegotiatedContentResult<string>;
    Assert.AreEqual("", contentResult.Content);
}

Example 2: javascript dotify object

function dotify(obj) {
    const res = {};
    function recurse(obj, current) {
        for (const key in obj) {
            const value = obj[key];
            if(value != undefined) {
                const newKey = (current ? current + '.' + key : key);
                if (value && typeof value === 'object') {
                    recurse(value, newKey);
                } else {
                    res[newKey] = value;
                }
            }
        }
    }
    recurse(obj);
    return res;
}
dotify({'a':{'b1':{'c':1},'b2':{'c':1}}}) //{'a.b1.c':1,'a.b2.c':1}

Example 3: anonymous object java example

//for Java 10
boolean result = true;

var objResult = new Object() {
    boolean success = result;
};

System.out.println(objResult.success);

Tags:

Php Example