@Override public StructuredJsonGenerator writeValue(Date date, TimestampFormat timestampFormat) { try { switch (timestampFormat) { case UNIX_TIMESTAMP_IN_MILLIS: generator.writeNumber(DateUtils.formatUnixTimestampInMills(date)); break; case ISO_8601: generator.writeString(DateUtils.formatISO8601Date(date)); break; case RFC_822: generator.writeString(DateUtils.formatRFC822Date(date)); break; case UNIX_TIMESTAMP: default: generator.writeNumber(DateUtils.formatServiceSpecificDate(date)); } } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(Date date, TimestampFormat timestampFormat) { try { switch (timestampFormat) { case UNIX_TIMESTAMP_IN_MILLIS: generator.writeNumber(DateUtils.formatUnixTimestampInMills(date)); break; case ISO_8601: generator.writeString(DateUtils.formatISO8601Date(date)); break; case RFC_822: generator.writeString(DateUtils.formatRFC822Date(date)); break; case UNIX_TIMESTAMP: default: generator.writeNumber(DateUtils.formatServiceSpecificDate(date)); } } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
/** * Jackson doesn't have native support for timestamp. As per the RFC 7049 * (https://tools.ietf.org/html/rfc7049#section-2.4.1) we will need to * write a tag and write the epoch. */ @Override public StructuredJsonGenerator writeValue(Date date, TimestampFormat timestampFormat) { if (!(getGenerator() instanceof CBORGenerator)) { throw new IllegalStateException("SdkCborGenerator is not created with a CBORGenerator."); } CBORGenerator generator = (CBORGenerator) getGenerator(); try { generator.writeTag(CBOR_TAG_TIMESTAP); generator.writeNumber(date.getTime()); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(BigDecimal value) { try { /** * Note that this is not how the backend represents BigDecimal types. On the wire * it's normally a JSON number but this causes problems with certain JSON implementations * that parse JSON numbers as floating points automatically. (See API-433) */ generator.writeString(value.toString()); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(float val) { try { generator.writeNumber(val); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(double val) { try { generator.writeNumber(val); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(long val) { try { generator.writeNumber(val); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeEndObject() { try { generator.writeEndObject(); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(BigInteger value) { try { generator.writeNumber(value); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeFieldName(String fieldName) { try { generator.writeFieldName(fieldName); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(ByteBuffer bytes) { try { generator.writeBinary(BinaryUtils.copyBytesFrom(bytes)); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(int val) { try { generator.writeNumber(val); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(String val) { try { generator.writeString(val); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeValue(short val) { try { generator.writeNumber(val); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeStartObject() { try { generator.writeStartObject(); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeEndArray() { try { generator.writeEndArray(); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
public SdkJsonGenerator(JsonFactory factory, String contentType) { try { /** * A {@link JsonGenerator} created is by default enabled with * UTF-8 encoding */ this.generator = factory.createGenerator(baos); this.contentType = contentType; } catch (IOException e) { throw new JsonGenerationException(e); } }
/** * Closes the generator and flushes to write. Must be called when finished writing JSON * content. */ private void close() { try { generator.close(); } catch (IOException e) { throw new JsonGenerationException(e); } }
@Override public StructuredJsonGenerator writeValue(boolean bool) { try { generator.writeBoolean(bool); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public StructuredJsonGenerator writeNull() { try { generator.writeNull(); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }