@SuppressWarnings("unchecked")
    // visible for testing
    public StitchRequestBody createStitchRequestBody(final Message inMessage) {
        if (inMessage.getBody() instanceof StitchRequestBody) {
            return createStitchRequestBodyFromStitchRequestBody(inMessage.getBody(StitchRequestBody.class), inMessage);
        }

        if (inMessage.getBody() instanceof StitchMessage) {
            return createStitchRequestBodyFromStitchMessages(Collections.singletonList(inMessage.getBody(StitchMessage.class)),
                    inMessage);
        }

        if (inMessage.getBody() instanceof Iterable) {
            return createStitchRequestBodyFromIterable(inMessage.getBody(Iterable.class), inMessage);
        }

        if (inMessage.getBody() instanceof Map) {
            return createStitchRecordFromMap(inMessage.getBody(Map.class), inMessage);
        }

        throw new IllegalArgumentException("Message body data `" + inMessage.getBody() + "` type is not supported");
    }
@Test
    void testIfCreateIfMapSet() {
        final StitchConfiguration configuration = new StitchConfiguration();

        final Map<String, Object> properties = new LinkedHashMap<>();
        properties.put("id", Collections.singletonMap("type", "integer"));
        properties.put("name", Collections.singletonMap("type", "string"));
        properties.put("age", Collections.singletonMap("type", "integer"));
        properties.put("has_magic", Collections.singletonMap("type", "boolean"));

        final Map<String, Object> message = new LinkedHashMap<>();
        message.put(StitchMessage.DATA, Collections.singletonMap("id", 2));
        message.put(StitchMessage.SEQUENCE, 1L);

        final Map<String, Object> data = new LinkedHashMap<>();
        data.put(StitchRequestBody.TABLE_NAME, "my_table");
        data.put(StitchRequestBody.SCHEMA, Collections.singletonMap("properties", properties));
        data.put(StitchRequestBody.MESSAGES,
                Collections.singletonList(message));
        data.put(StitchRequestBody.KEY_NAMES, Collections.singletonList("test_key"));

        final Exchange exchange = new DefaultExchange(context);
        exchange.getMessage().setBody(data);

        final StitchProducerOperations operations = new StitchProducerOperations(new TestClient(), configuration);

        final String createdJson
                = JsonUtils.convertMapToJson(operations.createStitchRequestBody(exchange.getMessage()).toMap());

        assertEquals("{\"table_name\":\"my_table\",\"schema\":{\"properties\":{\"id\":{\"type\":\"integer\"},"
                     + "\"name\":{\"type\":\"string\"},\"age\":{\"type\":\"integer\"},\"has_magic\""
                     + ":{\"type\":\"boolean\"}}},\"messages\":[{\"action\":\"upsert\",\"sequence\":1,"
                     + "\"data\":{\"id\":2}}],\"key_names\":[\"test_key\"]}",
                createdJson);
    }