JSONObject.valueToString(Object) is a public static method. It is expected, but not required, that it will only be called for JSONObject values. The following code will result in a ClassCastException in the JSONObject(Map<String, Object>) constructor:
Map<Integer, String> myMap = new HashMap<Integer, String>();
myMap.put(1, "myValue");
String str = JSONObject.valueToString(myMap);