-
Notifications
You must be signed in to change notification settings - Fork 125
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
Spring Cloud Stream throws exception when converting a message to a manifold created object from JSON #572
Comments
Added
|
The problem is probably related to |
Tried a little experiment ... I commented out the no-argument constructor for the Within
This doesn't prove or disprove your comment ... but it does say that at the very least, Spring Cloud Stream is expecting a no-argument constructor. |
I'm pretty confident the issue with PersonManifold is due to the fact that it's an interface, spring needs a concrete class to construct. I don't use spring, however I took a brief look and it appears you may be able to provide a custom binder so you can override handleMessage() and do whatever you like. That being the case, you could implement bindings for manifold-json, something like this: Class<?> beanClass = get json interface from spring;
String jsonString = new String(jsonByteArray);
Object jsonObj = manifold.json.rt.Json.fromJson(jsonString);
Object obj = manifold.ext.rt.RuntimeMethods.coerce(jsonObj, beanClass);
return obj; With this in place your original exampleEventConsumer example should work. |
Brilliant! Created the following classes
and
By registering the custom converter as a bean, the above code automatically used it for message conversion. |
Workaround provided above to use manifold with JSON. |
Spring Cloud Stream can't automatically convert a manifold created object from JSON to POJO.
First the code with a POJO called
Person
...And the
Person
POJO inPerson.Java
:The above works as expected ... a JSON message that is sent into the broker is automically converted to a
Person
object.Then, swapping in
PersonManifold
from JSONAnd corresponding change in callback ...
And sending the same message as above, results in a failure to convert the message:
The text was updated successfully, but these errors were encountered: