APISonar


org.apache.pulsar.client.api.Schema.JSON

> org > apache > pulsar > client > api > Schema > JSON
org APIs apache APIs pulsar APIs client APIs api APIs Schema APIs JSON APIs

Example 1
public void testJarPojoSchemaUploadJson() throws Exception {

        ContainerExecResult containerExecResult = pulsarCluster.runAdminCommandOnAnyBroker(
                "schemas",
                "extract", "--jar", "/pulsar/examples/api-examples.jar", "--type", "json",
                "--classname", "org.apache.pulsar.functions.api.examples.pojo.Tick",
                "persistent://public/default/pojo-json");

        Assert.assertEquals(containerExecResult.getExitCode(), 0);
        testPublishAndConsume("persistent://public/default/pojo-json", "json", Schema.JSON(Tick.class));
    }
Example 2
public static String getJsonSchemaInfo(SchemaDefinition schemaDefinition) {

        return new String(Schema.JSON(schemaDefinition).getSchemaInfo().getSchema(),
                          StandardCharsets.UTF_8);
    }
Example 3
public void testGenericJsonSchema() {
        Schema<Foo> encodeSchema = Schema.JSON(Foo.class);
        GenericSchema decodeSchema = GenericSchemaImpl.of(encodeSchema.getSchemaInfo());
        testEncodeAndDecodeGenericRecord(encodeSchema, decodeSchema);
    }
Example 4
public void testGetSchema(String serviceUrl) throws Exception {
        @Cleanup
        PulsarClientImpl client = (PulsarClientImpl) PulsarClient.builder().serviceUrl(serviceUrl).build();

        assertEquals(client.getSchema("non-existing-topic").join(), Optional.empty());
        assertEquals(client.getSchema(topicBytes).join(), Optional.empty());
        assertEquals(client.getSchema(topicString).join(), Optional.of(Schema.STRING.getSchemaInfo()));
        assertEquals(client.getSchema(topicJson).join(), Optional.of(Schema.JSON(MyClass.class).getSchemaInfo()));
        assertEquals(client.getSchema(topicAvro).join(), Optional.of(Schema.AVRO(MyClass.class).getSchemaInfo()));
    }