-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Mailing list thread: https://lists.apache.org/thread/ydslz3h8ymjjwm5ng02kwszmc5j5hy30
Motivation
Now, don‘t register logical type conversions when use SchemaDefinition.<T>builder().withJsonDef()
to create the schema, beacase it without classLoader param. (e.g: #15899)
See:
pulsar/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/reader/AvroReader.java
Lines 58 to 68 in 04aa9e8
public AvroReader(Schema writerSchema, Schema readerSchema, ClassLoader classLoader, | |
boolean jsr310ConversionEnabled) { | |
this.schema = readerSchema; | |
if (classLoader != null) { | |
ReflectData reflectData = new ReflectData(classLoader); | |
AvroSchema.addLogicalTypeConversions(reflectData, jsr310ConversionEnabled); | |
this.reader = new ReflectDatumReader<>(writerSchema, readerSchema, reflectData); | |
} else { | |
this.reader = new ReflectDatumReader<>(writerSchema, readerSchema); | |
} | |
} |
We can add the classLoader field for SchemaDefinition, user can manually pass a classLoader to register logical type conversions
Goal
This proposes to add the classLoader field for SchemaDefinition. When using SchemaDefinition.<T>builder().withJsonDef()
to create the schema it must manually specify a classLoader otherwise, the converter will not work.
The priority of the classLoader field will be higher than by the pojoClass.getClassLoader()
.
API Changes
public class SchemaDefinitionBuilder {
//....
/**
* Set schema of pojo classLoader.
*
* @param classLoader pojo classLoader
*
* @return schema definition builder
*/
SchemaDefinitionBuilder<T> withClassLoader(ClassLoader classLoader);
}
public class SchemaDefinition {
//....
/**
* Get pojo classLoader.
*
* @return pojo schema
*/
ClassLoader getClassLoader();
}
Implementation
Add the classloader field for SchemaDefinition.