@Override
    protected void writeInternal(
            Object object,
            HttpOutputMessage outputMessage
    ) throws IOException, HttpMessageNotWritableException {
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
            HttpHeaders headers = outputMessage.getHeaders();

            int contentLength;
            if (object instanceof String && com.alibaba.fastjson2.JSON.isValidObject((String) object)) {
                byte[] strBytes = ((String) object).getBytes(fastJsonConfig.getCharset());
                contentLength = strBytes.length;
                outputMessage.getBody().write(strBytes, 0, strBytes.length);
            } else if (object instanceof byte[] && com.alibaba.fastjson2.JSON.isValid((byte[]) object)) {
                byte[] strBytes = (byte[]) object;
                contentLength = strBytes.length;
                outputMessage.getBody().write(strBytes, 0, strBytes.length);
            } else {
                if (object instanceof JSONPObject) {
                    headers.setContentType(APPLICATION_JAVASCRIPT);
                }

                contentLength = JSON.writeJSONString(
                        baos, object,
                        fastJsonConfig.getDateFormat(),
                        fastJsonConfig.getSerializeFilters(),
                        fastJsonConfig.getSerializerFeatures()
                );
            }

            if (headers.getContentLength() < 0 && fastJsonConfig.isWriteContentLength()) {
                headers.setContentLength(contentLength);
            }

            baos.writeTo(outputMessage.getBody());
        } catch (JSONException ex) {
            throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
        } catch (IOException ex) {
            throw new HttpMessageNotWritableException("I/O error while writing output message", ex);
        }
    }
@param fastJsonConfig the fastJsonConfig to set.
fastjson1-compatible/src/main/java/com/alibaba/fastjson/support/spring/FastJsonHttpMessageConverter.java