public static <T> JSONSchema<T> of(SchemaDefinition<T> schemaDefinition) {
        SchemaReader<T> reader = schemaDefinition.getSchemaReaderOpt()
                .orElseGet(() -> new JacksonJsonReader<>(jsonMapper(), schemaDefinition.getPojo()));
        SchemaWriter<T> writer = schemaDefinition.getSchemaWriterOpt()
                .orElseGet(() -> new JacksonJsonWriter<>(jsonMapper()));
        return new JSONSchema<>(parseSchemaInfo(schemaDefinition, SchemaType.JSON), schemaDefinition.getPojo(),
                reader, writer);
    }
@Test
    public void testJsonGenericRecordBuilder() {
        JSONSchema<Seller> sellerJsonSchema = JSONSchema.of(Seller.class);

        RecordSchemaBuilder sellerSchemaBuilder = SchemaBuilder.record("seller");
        sellerSchemaBuilder.field("state").type(SchemaType.STRING);
        sellerSchemaBuilder.field("street").type(SchemaType.STRING);
        sellerSchemaBuilder.field("zipCode").type(SchemaType.INT64);
        SchemaInfo sellerSchemaInfo = sellerSchemaBuilder.build(SchemaType.JSON);
        GenericSchemaImpl sellerGenericSchema = GenericSchemaImpl.of(sellerSchemaInfo);

        JSONSchema<PC> pcJsonSchema = JSONSchema.of(PC.class);

        RecordSchemaBuilder pcSchemaBuilder = SchemaBuilder.record("pc");
        pcSchemaBuilder.field("brand").type(SchemaType.STRING);
        pcSchemaBuilder.field("model").type(SchemaType.STRING);
        pcSchemaBuilder.field("gpu").type(SchemaType.STRING);
        pcSchemaBuilder.field("year").type(SchemaType.INT64);
        pcSchemaBuilder.field("seller", sellerGenericSchema).type(SchemaType.JSON).optional();
        SchemaInfo pcGenericSchemaInfo = pcSchemaBuilder.build(SchemaType.JSON);
        GenericSchemaImpl pcGenericSchema = GenericSchemaImpl.of(pcGenericSchemaInfo);

        Seller seller = new Seller("USA","oakstreet",9999);
        PC pc = new PC("dell","g3",2020, GPU.AMD, seller);

        byte[] bytes = pcJsonSchema.encode(pc);
        Assert.assertTrue(bytes.length > 0);

        Object pc2 = pcJsonSchema.decode(bytes);
        assertEquals(pc, pc2);

        GenericRecord sellerRecord = sellerGenericSchema.newRecordBuilder()
                .set("state", "USA")
                .set("street", "oakstreet")
                .set("zipCode", 9999)
                .build();

        GenericRecord pcRecord = pcGenericSchema.newRecordBuilder()
                .set("brand", "dell")
                .set("model","g3")
                .set("year", 2020)
                .set("gpu", GPU.AMD)
                .set("seller", sellerRecord)
                .build();

        byte[] bytes3 = pcGenericSchema.encode(pcRecord);
        Assert.assertTrue(bytes3.length > 0);
        GenericRecord pc3Record = pcGenericSchema.decode(bytes3);

        for(Field field : pc3Record.getFields()) {
            assertTrue(pcGenericSchema.getFields().contains(field));
        }
        assertEquals("dell", pc3Record.getField("brand"));
        assertEquals("g3", pc3Record.getField("model"));
        assertEquals(2020, pc3Record.getField("year"));
        assertEquals(GPU.AMD.toString(), pc3Record.getField("gpu"));


        GenericRecord seller3Record = (GenericRecord) pc3Record.getField("seller");
        assertEquals("USA", seller3Record.getField("state"));
        assertEquals("oakstreet", seller3Record.getField("street"));
        assertEquals(9999, seller3Record.getField("zipCode"));

        assertTrue(pc3Record instanceof GenericJsonRecord);
        Assertions.assertThatCode(() -> pc3Record.getField("I_DO_NOT_EXIST")).doesNotThrowAnyException();
    }