Closed
Description
My Code
Below is my code. I want to use Object
to receive the message and use JSON Schema. However, in practice, I cannot use JSON Schema; instead, Byte Schema is used, even though I explicitly specified schemaType = SchemaType.JSON
.
@PulsarListener(topics = "persistent://public/default/test-topic",
subscriptionName = "test-subscription",
subscriptionType = SubscriptionType.Shared,
schemaType = SchemaType.JSON
)
public void listen(Object message) {
System.out.println("Received message: " + message);
}
Problem Analysis
After reading the source code, the issue might be here:
If rawClass
is Object.class, isContainerType
will return true, leading to a ResolvableType with a null rawClass. This eventually causes an error in the SchemaResolver when parsing the Schema (essentially resulting in JSONSchema.of(null);
), which leads to the use of the default ByteSchema
.
My suggestion is: the isContainerType
method should check whether rawClass is Object. If it is, return false directly; otherwise, continue checking isAssignableFrom
.
Expectations
- The parameter of the listener method should be able to use Object and use JSON Schema.
- If JSON Schema is explicitly specified in
@PulsarListener
or elsewhere, but SchemaResolver cannot resolve it correctly, an exception should be thrown instead of automatically using Byte Schema as a fallback. - If no Schema Type is explicitly specified and SchemaResolver fails to resolve it correctly, a warning-level log should be output instead of a debug-level log.