-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue #6842] feat(schema): allow for schema reader and writer registration on SchemaDefinition #6905
Conversation
…maDefinition With this feature it is possible to configure own SchemaReader and SchemaWriter on SchemaDefinition instantiation. With this it is possible to e.g. reuse already configured Jackson ObjectMapper instances.
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/reader/JacksonJsonReader.java
Show resolved
Hide resolved
...r-client/src/main/java/org/apache/pulsar/client/impl/schema/SchemaDefinitionBuilderImpl.java
Outdated
Show resolved
Hide resolved
...r-client/src/main/java/org/apache/pulsar/client/impl/schema/SchemaDefinitionBuilderImpl.java
Outdated
Show resolved
Hide resolved
* | ||
* @return optional containing configured schema reader or empty optional if none is configure | ||
*/ | ||
Optional<SchemaReader<T>> getSchemaReaderOpt(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface is used for more than just JSON schemas, right? If so, it will be confusing for users to be able to set a reader and writer for any type of schema when they will only be used for JSON schemas and ignored otherwise. So we either need to support this broadly, or instead we can overload JSONSchema.of()
for a more targeted approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface can be used for other schemas as well, but both SchemaReader and SchemaWriter as well. I see what you mean, did not recognize the Producer and Consumer instantiators with Schema as parameter. But I am not sure if Schema class is meant to be used like that from outside the framework. As they already introduced some default Schema instantiators in the client api Schema class, I would not promote Schema.of for public use, as it is an internal of the framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, you'll probably want to overload Schema.JSON(Class<T>)
and Schema.JSON(SchemaDefinition)
as well as JSONSchema.of()
. All of these are referenced in the docs so presumably they are meant for public use. (Though I would have guessed JSONSchema.of
is not meant for public use since it's in the impl
package. 🤷)
@hansenc Thank you for your review and feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks great! Can you add unit tests for validating that the provided schema reader and writer are actually used for serialization and deserialization?
Thank your for your review! I will add some tests soon. |
Added unit and integration tests for SchemaReader and SchemaWriter registration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good. I just left a minor comment.
import org.apache.pulsar.client.api.PulsarClient; | ||
import org.apache.pulsar.client.api.PulsarClientException; | ||
import org.apache.pulsar.client.api.SubscriptionType; | ||
import org.apache.pulsar.client.api.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using import .*
…registration on SchemaDefinition (apache#6905) Fixes apache#6842 ### Motivation and Modifications With this feature it is possible to configure own SchemaReader and SchemaWriter on SchemaDefinition instantiation. With this it is possible to e.g. reuse already configured Jackson ObjectMapper instances.
…registration on SchemaDefinition (apache#6905) Fixes apache#6842 ### Motivation and Modifications With this feature it is possible to configure own SchemaReader and SchemaWriter on SchemaDefinition instantiation. With this it is possible to e.g. reuse already configured Jackson ObjectMapper instances.
Fixes #6842
Motivation and Modifications
With this feature it is possible to configure own SchemaReader and SchemaWriter on SchemaDefinition instantiation. With this it is possible to e.g. reuse already configured Jackson ObjectMapper instances.
Does this pull request potentially affect one of the following parts:
If
yes
was chosen, please highlight the changesDocumentation