@SuppressWarnings({"unchecked", "rawtypes"})
    static Object toJSON(Object object, JSONWriter.Feature... features) {
        if (object == null) {
            return null;
        }
        if (object instanceof JSONObject || object instanceof JSONArray) {
            return object;
        }

        JSONWriter.Context writeContext = features == null ?
                JSONFactory.createWriteContext() : JSONFactory.createWriteContext(features);
        Class<?> valueClass = object.getClass();
        ObjectWriter<?> objectWriter = writeContext.getObjectWriter(valueClass, valueClass);
        if (objectWriter instanceof ObjectWriterAdapter
                && !writeContext.isEnabled(JSONWriter.Feature.ReferenceDetection)
                && (objectWriter.getFeatures() & JSONWriter.Feature.WriteClassName.mask) == 0) {
            ObjectWriterAdapter objectWriterAdapter = (ObjectWriterAdapter) objectWriter;
            return objectWriterAdapter.toJSONObject(object, writeContext.features);
        }

        String str;
        try (JSONWriter writer = JSONWriter.of(writeContext)) {
            objectWriter.write(writer, object, null, null, writeContext.features);
            str = writer.toString();
        } catch (NullPointerException | NumberFormatException ex) {
            throw new JSONException("toJSONString error", ex);
        }

        return parse(str);
    }
Converts the specified object to a {@link JSONArray} or
{@link JSONObject}. Returns {@code null} if received object is {@code null}

@param object the specified object to be converted
@param features the specified features is applied to serialization
@return {@link JSONArray} or {@link JSONObject} or {@code null}
core/src/main/java/com/alibaba/fastjson2/JSON.java