Question

I am iterating over a quickfix Message. For a given field, how do I fetch the value for that field without knowing the type?
The quickfix.Message has methods like 'Double getDouble(int field), String getString(int field)' etc also, methods like DoubleField getField(DoubleField), StringField getField(StringField ) etc.
I was expecting a method like 'Object get(int field)' which returns Object
How do i retrieve the value without knowing the field type?

Was it helpful?

Solution

Short answer: getString(int field) is actually the generic method you're looking for. You can call it on any field that is present. Because when you think about it, a FIX message is just a bunch of fields serialized to strings and concatenated, right?

Longer answer: FIX messages, internally, just store the fields as strings. When you store a field to a Message, it doesn't keep your Field object references; it just stores it as a string again. Similarly, when a message is received, it doesn't allocate a bunch of new Field objects... that's a waste of time and memory. The field objects are created on-demand when you query for them, and non-string fields are converted when you query for them.

When you call getInt(), what actually happens is that the method extracts the field's string value and converts it to an int then returns it. Similarly, for getField(IntField), it extracts the string, converts it to int, then constructs a new IntField and returns that.

All fields are sent to you from the counterparty as a string. Thus, getString(int field) is perfectly generic, and gives you all the information about the field that there is.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top