@Test
public void testUnEscape() throws ScriptException, NoSuchMethodException
{

    Map<String,Object> jsonObj = new LinkedHashMap<>();
    String[] strs = {"a\\u0041", "d\\u{41}", "e\\v", "f\\'"};
    JSONConfig cfg = new JSONConfig().setUnEscapeWherePossible(true);
    for ( String str : strs ){
        jsonObj.clear();
        jsonObj.put("x", str+'Z');
        String json = JSONUtil.toJSON(jsonObj, cfg);
        char firstChar = str.charAt(0);
        String result;
        switch ( firstChar ){
            case 'e':
                // \v unescaped will be re-escaped as a Unicode code unit.
                result = firstChar + "\\u000B";
                break;
            case 'f':
                result = firstChar + "'";
                break;
            default:
                result = firstChar + "A";
                break;
        }
        assertThat(json, is("{\"x\":\""+result+"Z\"}"));
    }
    // test that these get fixed regardless.
    cfg.setUnEscapeWherePossible(false)
       .setPassThroughEscapes(true);
    // test octal/hex unescape.
    for ( int i = 0; i < 256; i++ ){
        jsonObj.clear();
        jsonObj.put("x", String.format("a\\%oZ", i));
        jsonObj.put("y", String.format("a\\x%02XZ", i));
        String result = StringProcessor.getEscape((char)i);
        if ( result == null ){
            result = i < 0x20 ? String.format("\\u%04X", i) : String.format("%c", (char)i);
        }
        String json = JSONUtil.toJSON(jsonObj, cfg);
        validateJSON(json);
        assertThat(json, is("{\"x\":\"a"+result+"Z\",\"y\":\"a"+result+"Z\"}"));
    }
}