I have emitter over http which is emitting events of different object types(different subclasses). A webclient which is subscribe to this stream need to check the type of event transmitted(map to type of object). How to achieve it as instance of operator is not working in this case
Asked
Active
Viewed 585 times
1 Answers
0
I have emitter over http which is emitting events of different object types(different subclasses)
If the emitter is over HTTP, then there's no concept of types - the events will be strings of data (serialised in some way of course, probably using JSON.) You need to tell the code what type it needs to use to deserialise - hence the existence of the class parameter on bodyToFlux()
.
If you're not sure of the type, then you can use bodyToFlux(Map.class)
to convert the JSON to a map - you can then inspect the map to work out what POJO you want to convert to, and go from there.

Michael Berry
- 70,193
- 21
- 157
- 216
-
1Just another suggestion over this, if you have control over the http objects, you can finalize a field in the object , the value of which can help you resolve the type of class at receiver end. – Aditya Rewari May 28 '20 at 13:06
-
1Say, you can have a field name ```action``` and the value of this, will decide, what VO are they stored on to ! – Aditya Rewari May 28 '20 at 13:07