@Test public void SyncTokenSerializer( @Mock JsonGenerator jgen, @Mock SerializerProvider sp) throws IOException { SyncTokenSerializer serializer = new SyncTokenSerializer(); SyncToken source = new SyncToken(UUID.randomUUID().toString()); serializer.serialize(source, jgen, sp); verify(jgen).writeStartObject(); verify(jgen).writeFieldName("value"); verify(jgen).writeEndObject(); boolean bool = false; source = new SyncToken(bool); serializer.serialize(source, jgen, sp); verify(jgen).writeBoolean(bool); double doubleNum = 9000.1; source = new SyncToken(doubleNum); serializer.serialize(source, jgen, sp); verify(jgen).writeNumber(doubleNum); long longNum = 9001; source = new SyncToken(longNum); serializer.serialize(source, jgen, sp); verify(jgen).writeNumber(longNum); int intNum = 9000; source = new SyncToken(intNum); serializer.serialize(source, jgen, sp); verify(jgen).writeNumber(intNum); byte[] bytes = new byte[] { 9, 0, 0, 1 }; source = new SyncToken(bytes); serializer.serialize(source, jgen, sp); verify(jgen, times(2)).writeString(anyString()); }
@Override public void serialize(final SyncToken source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); jgen.writeFieldName("value"); if (source.getValue() == null) { jgen.writeNull(); } else if (source.getValue() instanceof Boolean) { jgen.writeBoolean((Boolean) source.getValue()); } else if (source.getValue() instanceof Double) { jgen.writeNumber((Double) source.getValue()); } else if (source.getValue() instanceof Long) { jgen.writeNumber((Long) source.getValue()); } else if (source.getValue() instanceof Integer) { jgen.writeNumber((Integer) source.getValue()); } else if (source.getValue() instanceof byte[]) { jgen.writeString(Base64.getEncoder().encodeToString((byte[]) source.getValue())); } else { jgen.writeString(source.getValue().toString()); } jgen.writeEndObject(); }
SyncTokenSerializer extends JsonSerializer<SyncToken> { @Override public void serialize(final SyncToken source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); jgen.writeFieldName("value"); if (source.getValue() == null) { jgen.writeNull(); } else if (source.getValue() instanceof Boolean) { jgen.writeBoolean((Boolean) source.getValue()); } else if (source.getValue() instanceof Double) { jgen.writeNumber((Double) source.getValue()); } else if (source.getValue() instanceof Long) { jgen.writeNumber((Long) source.getValue()); } else if (source.getValue() instanceof Integer) { jgen.writeNumber((Integer) source.getValue()); } else if (source.getValue() instanceof byte[]) { jgen.writeString(Base64.getEncoder().encodeToString((byte[]) source.getValue())); } else { jgen.writeString(source.getValue().toString()); } jgen.writeEndObject(); } }
SyncTokenSerializer extends JsonSerializer<SyncToken> { @Override public void serialize(final SyncToken source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); jgen.writeFieldName("value"); if (source.getValue() == null) { jgen.writeNull(); } else if (source.getValue() instanceof Boolean) { jgen.writeBoolean((Boolean) source.getValue()); } else if (source.getValue() instanceof Double) { jgen.writeNumber((Double) source.getValue()); } else if (source.getValue() instanceof Long) { jgen.writeNumber((Long) source.getValue()); } else if (source.getValue() instanceof Integer) { jgen.writeNumber((Integer) source.getValue()); } else if (source.getValue() instanceof byte[]) { jgen.writeString(Base64.getEncoder().encodeToString((byte[]) source.getValue())); } else { jgen.writeString(source.getValue().toString()); } jgen.writeEndObject(); }  }
SyncTokenSerializer extends JsonSerializer<SyncToken> { @Override public void serialize(final SyncToken source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); jgen.writeFieldName("value"); if (source.getValue() == null) { jgen.writeNull(); } else if (source.getValue() instanceof Boolean) { jgen.writeBoolean((Boolean) source.getValue()); } else if (source.getValue() instanceof Double) { jgen.writeNumber((Double) source.getValue()); } else if (source.getValue() instanceof Long) { jgen.writeNumber((Long) source.getValue()); } else if (source.getValue() instanceof Integer) { jgen.writeNumber((Integer) source.getValue()); } else if (source.getValue() instanceof byte[]) { jgen.writeString(Base64.getEncoder().encodeToString((byte[]) source.getValue())); } else { jgen.writeString(source.getValue().toString()); } jgen.writeEndObject(); }  @Override void serialize(final SyncToken source, final JsonGenerator jgen, final SerializerProvider sp); }
SyncTokenSerializer extends JsonSerializer<SyncToken> { @Override public void serialize(final SyncToken source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); jgen.writeFieldName("value"); if (source.getValue() == null) { jgen.writeNull(); } else if (source.getValue() instanceof Boolean) { jgen.writeBoolean((Boolean) source.getValue()); } else if (source.getValue() instanceof Double) { jgen.writeNumber((Double) source.getValue()); } else if (source.getValue() instanceof Long) { jgen.writeNumber((Long) source.getValue()); } else if (source.getValue() instanceof Integer) { jgen.writeNumber((Integer) source.getValue()); } else if (source.getValue() instanceof byte[]) { jgen.writeString(Base64.getEncoder().encodeToString((byte[]) source.getValue())); } else { jgen.writeString(source.getValue().toString()); } jgen.writeEndObject(); }  @Override void serialize(final SyncToken source, final JsonGenerator jgen, final SerializerProvider sp);  }