use of com.twosigma.beakerx.CodeCell in project beakerx by twosigma.
the class BeakerCodeCellListDeserializer method deserialize.
@Override
public BeakerCodeCellList deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = mapper.readTree(jp);
List<CodeCell> l = new ArrayList<CodeCell>();
if (node.isArray()) {
for (JsonNode o : node) {
Object obj = objectSerializerProvider.get().deserialize(o, mapper);
if (obj instanceof CodeCell)
l.add((CodeCell) obj);
}
}
BeakerCodeCellList r = new BeakerCodeCellList();
r.theList = l;
return r;
}
use of com.twosigma.beakerx.CodeCell in project beakerx by twosigma.
the class CodeCellListDeserializerTest method deserialize_resultObjectHasBeakerCodeCellList.
@Test
public void deserialize_resultObjectHasBeakerCodeCellList() throws Exception {
// given
ObjectMapper mapper = new ObjectMapper();
String str = "[{\"type\":\"CodeCell\",\"execution_count\":null," + "\"cell_type\":null,\"outputs\":null,\"metadata\":null,\"source\":null}," + "{\"type\":\"CodeCell\",\"execution_count\":null,\"" + "cell_type\":null,\"outputs\":null,\"metadata\":null,\"source\":null}]";
BeakerCodeCellListDeserializer deserializer = new BeakerCodeCellListDeserializer(() -> {
BasicObjectSerializer boSerializer = new BasicObjectSerializer();
boSerializer.addTypeDeserializer(new CodeCell.DeSerializer(boSerializer));
return boSerializer;
});
// when
BeakerCodeCellList bkList = (BeakerCodeCellList) deserializer.deserialize(mapper.getFactory().createParser(str), null);
// then
Assertions.assertThat(bkList).isNotNull();
Assertions.assertThat(bkList.theList.size()).isEqualTo(2);
}
use of com.twosigma.beakerx.CodeCell in project beakerx by twosigma.
the class CodeCellDeSerializerTest method deserialize_resultObjectHasExecutionCount.
@Test
public void deserialize_resultObjectHasExecutionCount() throws Exception {
String execCount = "5";
// given
ObjectMapper mapper = new ObjectMapper();
JsonNode actualObj = mapper.readTree("{\"type\":\"CodeCell\",\"execution_count\":" + execCount + ",\"cell_type\":null," + "\"outputs\":null,\"metadata\":null,\"source\":null}");
CodeCell.DeSerializer deserializer = new CodeCell.DeSerializer(new BasicObjectSerializer());
// when
CodeCell bkCell = (CodeCell) deserializer.deserialize(actualObj, mapper);
// then
Assertions.assertThat(bkCell).isNotNull();
Assertions.assertThat(bkCell.getExecutionCount()).isEqualTo(execCount);
}
use of com.twosigma.beakerx.CodeCell in project beakerx by twosigma.
the class CodeCellSerializerTest method setUp.
@Before
public void setUp() throws Exception {
KernelManager.register(new KernelTest());
codeCell = new CodeCell();
}
use of com.twosigma.beakerx.CodeCell in project beakerx by twosigma.
the class GetCodeCellsHandler method getBeakerCodeCells.
private List<CodeCell> getBeakerCodeCells(Object value) {
List<CodeCell> codeCellList = null;
StringWriter sw = new StringWriter();
JsonGenerator jgen = null;
try {
jgen = objectMapper.getFactory().createGenerator(sw);
objectSerializer.writeObject(value, jgen, true);
jgen.flush();
sw.flush();
codeCellList = Arrays.asList(objectMapper.readValue(sw.toString(), CodeCell[].class));
} catch (IOException e) {
e.printStackTrace();
}
return codeCellList;
}
Aggregations