I’m attempting to expose MarketData objects via a web service. As far as I can see, JSON serialization works fine. I’m having difficulties with deserializing the JSON back into a MarketData (specifically BuiltMarketData) object. Note: This works correctly for XML serialization/deserialization. The following code demonstrates the issue with JSON deserialization:
public MarketData getCalibratedMarketData(LocalDate valDate, Instance instance) {
CalculationRules rules = CalculationRules.of(StandardComponents.calculationFunctions(),
RatesMarketDataLookup.of(getCurveGroupDefinition(valDate)));
MarketDataRequirements reqs = MarketDataRequirements.of(rules,
getTrades(valDate, instance).toJavaList(),
ImmutableList.of(Column.of(Measures.PRESENT_VALUE)), refData);
MarketDataConfig marketDataConfig = MarketDataConfig.builder()
.add(groupName, getCurveGroupDefinition(valDate)).build();
return StandardComponents.marketDataFactory().create(reqs, marketDataConfig,
getMarketData(valDate, instance), refData);
}
Tests serialization and deserialization:
BuiltMarketData mktData = (BuiltMarketData) curveService.getCalibratedMarketData(valDate, instance);
String json = JodaBeanSer.COMPACT.jsonWriter().write(mktData);
mktData = JodaBeanSer.COMPACT.jsonReader().read(json, BuiltMarketData.class);
Attempting this throws an exception:
{
"timestamp": "2018-02-08T23:06:52.494+0000",
"status": 500,
"error": "Internal Server Error",
"exception": "java.lang.IllegalArgumentException",
"message": "Error parsing bean: com.opengamma.strata.calc.marketdata.BuiltMarketData::underlying, Error parsing bean: com.opengamma.strata.calc.marketdata.BuiltScenarioMarketData::underlying, Error parsing bean: com.opengamma.strata.data.scenario.ImmutableScenarioMarketData::values, Error parsing bean: com.opengamma.strata.data.scenario.SingleMarketDataBox::value, Error parsing bean: com.opengamma.strata.market.curve.CurveInputs::marketData, null",
"path": "/curves/calibrated-marketdata"
}