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
Add annotation for id class mapping #1549
Comments
Does the new Using Methods to Determine Types feature not meet your needs? private static final JavaType barType = TypeFactory.defaultInstance()
.constructType(Bar.class);
public static JavaType whichType(byte[] data, Headers headers) {
Header header = headers.lastHeader("foo");
if (header != null) {
return this.barType;
}
else {
return TypeFactory.defaultInstance().constructType(Object.class);
}
}
|
But that still requires you to define the mapping in a centralized place, right? |
I have now created the following for our project, which allows you to just annotate a class with @KafkaMessage and a type id:
Maybe something like the above could be adopted by the spring-kafka project? |
Sure; will take a look. |
Would be great to have such kind of support. Mapping and method resolutions are a bit intrusive compared to a single annotation. Any plans to have it in a coming version of Spring Kafka?
|
I am not sure I really understand the requirement here. The Perhaps a real use case would help me understand what the requirement is. |
Thanks for the reply. According to my understanding, the event type is propagated through the TypeId. So, instead, it would be great to have an identifier/name to uniquely identify the type. Maybe I missed something, but the main idea is to be agnostic of the real java type of the event. Let me know if you need more details. |
While it is true that the type id is set to the FQCN of the source class (by default), it can be changed to set a token via type mapping and, on the receiving side, the token can be mapped to the destination type. However, by default, the type id header is ignored and the type is inferred from the method signature. See Lines 60 to 74 in 30ee20d
|
Feature request
PROBLEM
Currently, mapping id's to classes is, for example, done through configuration beans. There a
TypePrecedence
,mapping
andTypeMapper
can be configured. For any additional message, you also have to add changes to your configuration.SUGGESTED SOLUTION
It would be nice if setting this configuration could be simplified by annotating a class with, for example:
Upon setting this annotation, the
TypePrecedence
and a defaultTypeMapper
could be set as well.The text was updated successfully, but these errors were encountered: