private static final String X_LABEL_FIELD = "xLabel";
private static final String Y_LABEL_FIELD = "yLabel";
@Override
public MutableFudgeMsg buildMessage(final FudgeSerializer serializer, final VolatilitySurfaceData<?, ?> object) {
final MutableFudgeMsg message = serializer.newMessage();
// the following forces it not to use a secondary type if one is available.
message.add(TARGET_FIELD, FudgeSerializer.addClassHeader(serializer.objectToFudgeMsg(object.getTarget()), object.getTarget().getClass()));
serializer.addToMessage(message, TARGET_FIELD, null, object.getTarget());
message.add(DEFINITION_FIELD, object.getDefinitionName());
message.add(SPECIFICATION_FIELD, object.getSpecificationName());
for (final Object x : object.getXs()) {
if (x != null) {
message.add(XS_FIELD, null, FudgeSerializer.addClassHeader(serializer.objectToFudgeMsg(x), x.getClass()));
}
}
for (final Object y : object.getYs()) {
if (y != null) {
message.add(YS_FIELD, null, FudgeSerializer.addClassHeader(serializer.objectToFudgeMsg(y), y.getClass()));
}
}
for (final Entry<?, Double> entry : object.asMap().entrySet()) {
final Pair<Object, Object> pair = (Pair<Object, Object>) entry.getKey();
final MutableFudgeMsg subMessage = serializer.newMessage();
if (pair.getFirst() != null && pair.getSecond() != null) {
subMessage.add(X_FIELD, null, serializer.objectToFudgeMsg(pair.getFirst()));
subMessage.add(Y_FIELD, null, serializer.objectToFudgeMsg(pair.getSecond()));
subMessage.add(VALUE_FIELD, null, entry.getValue());
message.add(VALUES_FIELD, null, subMessage);
}
}
message.add(X_LABEL_FIELD, object.getXLabel());
message.add(Y_LABEL_FIELD, object.getYLabel());