private static final String XS_FIELD = "xs";
private static final String YS_FIELD = "ys";
@Override
public MutableFudgeMsg buildMessage(final FudgeSerializer serializer, final VolatilitySurfaceDefinition<?, ?> 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()));
if (object.getTarget() instanceof Currency) {
final Currency ccy = (Currency) object.getTarget();
message.add(CURRENCY_FIELD, null, ccy.getCode());
} else {
// just for now...
message.add(CURRENCY_FIELD, null, Currency.USD.getCode());
}
message.add(NAME_FIELD, object.getName());
for (final Object x : object.getXs()) {
if (x instanceof Number) {
serializer.addToMessageWithClassHeaders(message, XS_FIELD, null, x);
} else {
message.add(XS_FIELD, null, FudgeSerializer.addClassHeader(serializer.objectToFudgeMsg(x), x.getClass()));
}
}
for (final Object y : object.getYs()) {
if (y instanceof Number) {
serializer.addToMessageWithClassHeaders(message, YS_FIELD, null, y);
} else {
message.add(YS_FIELD, null, FudgeSerializer.addClassHeader(serializer.objectToFudgeMsg(y), y.getClass()));
}
}
return message;
}