@Override public OutputDataRaw deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final JsonObject object = json.getAsJsonObject(); final OutputDataRaw dataRaw = new OutputDataRaw(); final JsonElement png = object.get("image/png"); if (png != null) { dataRaw.png = png.getAsString(); } dataRaw.html = getStringOrArray("text/html", object); dataRaw.svg = getStringOrArray("image/svg+xml", object); dataRaw.jpeg = getStringOrArray("image/jpeg", object); dataRaw.latex = getStringOrArray("text/latex", object); dataRaw.text = getStringOrArray("text/plain", object); return dataRaw; }
public static CellOutputRaw fromOutput(@NotNull final IpnbOutputCell outputCell, int nbformat) { final CellOutputRaw raw = new CellOutputRaw(); raw.metadata = outputCell.getMetadata(); if (raw.metadata == null && !(outputCell instanceof IpnbStreamOutputCell) && !(outputCell instanceof IpnbErrorOutputCell)) { raw.metadata = Collections.emptyMap(); } if (outputCell instanceof IpnbPngOutputCell) { if (nbformat == 4) { final OutputDataRaw dataRaw = new OutputDataRaw(); dataRaw.png = ((IpnbPngOutputCell) outputCell).getBase64String(); dataRaw.text = outputCell.getText(); raw.data = dataRaw; raw.execution_count = outputCell.getPromptNumber(); raw.output_type = outputCell.getPromptNumber() != null ? "execute_result" : "display_data"; } else { raw.png = ((IpnbPngOutputCell) outputCell).getBase64String(); raw.text = outputCell.getText(); } } else if (outputCell instanceof IpnbSvgOutputCell) { if (nbformat == 4) { final OutputDataRaw dataRaw = new OutputDataRaw(); dataRaw.text = outputCell.getText(); dataRaw.svg = ((IpnbSvgOutputCell) outputCell).getSvg(); raw.data = dataRaw; raw.execution_count = outputCell.getPromptNumber(); raw.output_type = outputCell.getPromptNumber() != null ? "execute_result" : "display_data"; } else { raw.svg = ((IpnbSvgOutputCell) outputCell).getSvg(); raw.text = outputCell.getText(); } } else if (outputCell instanceof IpnbJpegOutputCell) { if (nbformat == 4) { final OutputDataRaw dataRaw = new OutputDataRaw(); dataRaw.text = outputCell.getText(); dataRaw.jpeg = Lists.newArrayList(((IpnbJpegOutputCell) outputCell).getBase64String()); raw.data = dataRaw; } else { raw.jpeg = ((IpnbJpegOutputCell) outputCell).getBase64String(); raw.text = outputCell.getText(); } } else if (outputCell instanceof IpnbLatexOutputCell) { if (nbformat == 4) { final OutputDataRaw dataRaw = new OutputDataRaw(); dataRaw.text = outputCell.getText(); dataRaw.latex = ((IpnbLatexOutputCell) outputCell).getLatex(); raw.data = dataRaw; raw.execution_count = outputCell.getPromptNumber(); raw.output_type = "execute_result"; } else { raw.latex = ((IpnbLatexOutputCell) outputCell).getLatex(); raw.text = outputCell.getText(); raw.prompt_number = outputCell.getPromptNumber(); } } else if (outputCell instanceof IpnbStreamOutputCell) { if (nbformat == 4) { raw.name = ((IpnbStreamOutputCell) outputCell).getStream(); } else { raw.stream = ((IpnbStreamOutputCell) outputCell).getStream(); } raw.text = outputCell.getText(); raw.output_type = "stream"; } else if (outputCell instanceof IpnbHtmlOutputCell) { if (nbformat == 4) { final OutputDataRaw dataRaw = new OutputDataRaw(); dataRaw.html = ((IpnbHtmlOutputCell) outputCell).getHtmls(); dataRaw.text = outputCell.getText(); raw.data = dataRaw; raw.execution_count = outputCell.getPromptNumber(); } else { raw.html = ((IpnbHtmlOutputCell) outputCell).getHtmls(); } raw.output_type = nbformat == 4 ? "execute_result" : "pyout"; } else if (outputCell instanceof IpnbErrorOutputCell) { raw.output_type = nbformat == 4 ? "error" : "pyerr"; raw.evalue = ((IpnbErrorOutputCell) outputCell).getEvalue(); raw.ename = ((IpnbErrorOutputCell) outputCell).getEname(); raw.traceback = outputCell.getText(); } else if (outputCell instanceof IpnbOutOutputCell) { if (nbformat == 4) { raw.execution_count = outputCell.getPromptNumber(); raw.output_type = "execute_result"; final OutputDataRaw dataRaw = new OutputDataRaw(); dataRaw.text = outputCell.getText(); raw.data = dataRaw; } else { raw.output_type = "pyout"; raw.prompt_number = outputCell.getPromptNumber(); raw.text = outputCell.getText(); } } else { raw.text = outputCell.getText(); } return raw; }