@Override public DefaultSerializerProvider copy() { if (getClass() != Impl.class) { return super.copy(); } return new Impl(this); }
@Test public void serializeConstantLine_resultJsonHasType() throws IOException { //when ConstantLine constantLine = new ConstantLine() {}; constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("ConstantLine"); }
@Test public void serializeStrokeTypeLine_resultJsonHasStyle() throws IOException { //when line.setStyle(StrokeType.SOLID); lineSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("style")).isTrue(); Assertions.assertThat(actualObj.get("style").asText()).isEqualTo("SOLID"); }
@Test public void serializeRatioOfTreeMap_resultJsonHasRatio() throws IOException { //when treeMap.setRatio(2.0); treeMapSerializer.serialize(treeMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("ratio")).isTrue(); Assertions.assertThat(actualObj.get("ratio").asDouble()).isEqualTo(2.0); }
@Test public void serializeDrawOutlineCategoryBars_resultJsonHasOutline() throws IOException { //when CategoryBars categoryBars = new CategoryBars(); categoryBars.setDrawOutline(true); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline")).isTrue(); Assertions.assertThat(actualObj.get("outline").asBoolean()).isTrue(); }
@Test public void serializeFillCategoryBars_resultJsonHasFill() throws IOException { //when CategoryBars categoryBars = new CategoryBars(); categoryBars.setFill(true); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("fill")).isTrue(); Assertions.assertThat(actualObj.get("fill").asBoolean()).isTrue(); }
@Test public void serializeOrientationCategoryPlot_resultJsonHasOrientation() throws IOException { //when CategoryPlot categoryPlot = new CategoryPlot(); categoryPlot.setOrientation(PlotOrientationType.VERTICAL); categoryPlotSerializer.serialize(categoryPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("orientation")).isTrue(); Assertions.assertThat(actualObj.get("orientation").asText()).isEqualTo("VERTICAL"); }
@Test public void serializeColorOfText_resultJsonHasColor() throws IOException { //when text.setColor(Color.GREEN); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); }
@Test public void serializePointerAngleOfText_resultJsonHasPointerAngle() throws IOException { //when text.setPointerAngle(0.5); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("pointer_angle")).isTrue(); Assertions.assertThat(actualObj.get("pointer_angle").asDouble()).isEqualTo(0.5); }
@Test public void serializeGradientColor_resultJsonHasGradientColor() throws IOException { //when GradientColor gradientColor = new GradientColor(Arrays.asList(Color.GREEN, Color.BLUE)); gradientColorSerializer.serialize(gradientColor, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then ArrayNode arrayNode = (ArrayNode) mapper.readTree(sw.toString()); Assertions.assertThat(arrayNode).isNotEmpty(); Assertions.assertThat(arrayNode.get(0).get("rgb").asInt()).isEqualTo(Color.GREEN.getRGB()); } }
@Test public void serializeStrokeTypeCategoryStems_resultJsonHasStyle() throws IOException { //when CategoryStems categoryStems = new CategoryStems(); categoryStems.setStyle(StrokeType.SOLID); categoryStemsSerializer.serialize(categoryStems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("style")).isTrue(); Assertions.assertThat(actualObj.get("style").asText()).isEqualTo("SOLID"); }
@Test public void serializeBaseCategoryStems_resultJsonHasBase() throws IOException { //when CategoryStems categoryStems = new CategoryStems(); categoryStems.setBase(11); categoryStemsSerializer.serialize(categoryStems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("base")).isTrue(); Assertions.assertThat(actualObj.get("base").asInt()).isEqualTo(11); }
@Test public void serializeDisplayModeOfHistogram_resultJsonHasDisplayMode() throws IOException { //when histogram.setDisplayMode(Histogram.DisplayMode.STACK); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("displayMode")).isTrue(); Assertions.assertThat(actualObj.get("displayMode").asText()).isEqualTo("STACK"); }
@Test public void serializeLogOfHistogram_resultJsonHasLog() throws IOException { //when histogram.setLog(true); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("log")).isTrue(); Assertions.assertThat(actualObj.get("log").asBoolean()).isTrue(); }
@Test public void serializeRightCloseOfHistogram_resultJsonHasRightClose() throws IOException { //when histogram.setRightClose(true); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("right_close")).isTrue(); Assertions.assertThat(actualObj.get("right_close").asBoolean()).isTrue(); }
@Test public void serializeKeyTagsLineGraphics_resultJsonHasKeyTags() throws IOException { //when line.onKey("key01", "tag01"); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("keyTags")).isTrue(); Assertions.assertThat(actualObj.get("keyTags")).isNotEmpty(); }
@Test public void serializeVisibleLineGraphics_resultJsonHasVisible() throws IOException { //when line.setVisible(true); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("visible")).isTrue(); Assertions.assertThat(actualObj.get("visible").asBoolean()).isTrue(); }
@Test public void serializePositionOfLegendPosition_resultJsonHasPosition() throws IOException { //when legendPosition.setPosition(LegendPosition.Position.LEFT); legendPositionSerializer.serialize(legendPosition, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("position")).isTrue(); Assertions.assertThat(actualObj.get("position").asText()).isEqualTo("LEFT"); }
private SchemaAware getValueSerializer(Object valueAsJavaType) throws JsonMappingException { SerializerProvider serializerProvider = new DefaultSerializerProvider.Impl().createInstance(this.objectMapper.getSerializationConfig(), BeanSerializerFactory.instance); if (valueAsJavaType == null) { return NullSerializer.instance; } else if (valueAsJavaType instanceof Long) { // longs are 'integers' in schema terms JsonSerializer<Object> valueSerializer = serializerProvider.findValueSerializer(Integer.class, null); return (SchemaAware) valueSerializer; } else { Class<? extends Object> javaTypeForValue = valueAsJavaType.getClass(); JsonSerializer<Object> valueSerializer = serializerProvider.findValueSerializer(javaTypeForValue, null); return (SchemaAware) valueSerializer; } }
@Override public Impl createInstance(SerializationConfig config, SerializerFactory jsf) { return new Impl(this, config, jsf); } }