@Test
public void testReflect()
{

    JSONConfig cfg = new JSONConfig().setValidatePropertyNames(false)
                                     .setDetectDataStructureLoops(false)
                                     .setFastStrings(true)
                                     .setCacheReflectionData(false);
    JsonObject jsonObj = new JsonObject(1, cfg);
    jsonObj.add("f", new ReflectTestClass());
    ReflectedObjectMapBuilder.clearReflectionCache();
    // JNDI set up to only show fields a and e.
    String json = jsonObj.toJSON();
    assertThat(json, is("{\"f\":{\"a\":1,\"k\":25.0}}"));
    cfg.clearReflectClasses();
    cfg.addReflectClass(ReflectTestClass.class);
    cfg.setReflectionPrivacy(ReflectUtil.PRIVATE);
    json = jsonObj.toJSON();
    assertThat(json, is("{\"f\":{\"a\":1,\"b\":\"something\",\"c\":[],\"d\":null,\"f\":true}}"));
    cfg.setReflectionPrivacy(ReflectUtil.PACKAGE);
    json = jsonObj.toJSON();
    assertThat(json, is("{\"f\":{\"a\":1,\"b\":\"something\",\"c\":[],\"f\":true}}"));
    cfg.setReflectionPrivacy(ReflectUtil.PROTECTED);
    json = jsonObj.toJSON();
    assertThat(json, is("{\"f\":{\"a\":1,\"b\":\"something\",\"f\":true}}"));
    cfg.setReflectionPrivacy(ReflectUtil.PUBLIC);
    json = jsonObj.toJSON();
    assertThat(json, is("{\"f\":{\"a\":1,\"f\":true}}"));
    cfg = new JSONConfig(); // reload defaults.
    jsonObj.setJSONConfig(cfg);
    json = jsonObj.toJSON();
    assertThat(json, is("{\"f\":{\"a\":1,\"k\":25.0}}"));
    JSONConfigDefaults.getInstance().clearReflectClasses();
    ReflectedObjectMapBuilder.clearReflectionCache();
    cfg.setReflectUnknownObjects(false)
       .setReflectionPrivacy(ReflectUtil.PRIVATE)
       .addReflectClass(ReflectTestClass.class);
    //int iterations = 1000000;
    //int iterations = 100000;
    int iterations = 100;
    //int iterations = 0;
    /*
     * These timings get a little funky due to the way that the JVM cache's
     * things and improves its performance after doing the same thing
     * repeatedly.  Initially, it seems like maps are slow but eventually, as
     * the JVM does its optimization thing, they are faster.
     */
    ReflectTestClass r = new ReflectTestClass();
    runMapTiming(iterations, r, cfg);
    runReflectionTiming(iterations, r, cfg, false);
    runReflectionTiming(iterations, r, cfg, true);
    runMapTiming(iterations, r, cfg);
    runReflectionTiming(iterations, r, cfg, false);
    runReflectionTiming(iterations, r, cfg, true);
    // BigObject
    iterations = 1;
    cfg.clearReflectClasses()
       .addReflectClass(BigObject.class)
       .setFastStrings(false)
       .setEscapeNonAscii(true)
       .setUseECMA6(false);
    BigObject bigObj = new BigObject();
    runReflectionTiming(iterations, bigObj, cfg, false);
    runReflectionTiming(iterations, bigObj, cfg, true);
    runReflectionTiming(iterations, bigObj, cfg, false);
    runReflectionTiming(iterations, bigObj, cfg, true);
}