Java Code Examples for com.fasterxml.jackson.core.JsonGenerator#writeBinary()
The following examples show how to use
com.fasterxml.jackson.core.JsonGenerator#writeBinary() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JrsEmbeddedObject.java From jackson-jr with Apache License 2.0 | 5 votes |
@Override protected void write(JsonGenerator g, JacksonJrsTreeCodec codec) throws IOException { if (_value == null) { g.writeNull(); } else if (_value instanceof byte[]) { g.writeBinary((byte[]) _value); } else { g.writeObject(_value); } }
Example 2
Source File: Request.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuffer value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // value is never null, according to JsonSerializer contract jgen.writeBinary(value.array()); }
Example 3
Source File: ByteArraySerializer.java From autorest-clientruntime-for-java with MIT License | 5 votes |
@Override public void serialize(Byte[] value, JsonGenerator jgen, SerializerProvider provider) throws IOException { byte[] bytes = new byte[value.length]; for (int i = 0; i < value.length; i++) { bytes[i] = value[i]; } jgen.writeBinary(bytes); }
Example 4
Source File: UUIDSerializer.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void serialize(UUID value, JsonGenerator gen, SerializerProvider provider) throws IOException { // First: perhaps we could serialize it as raw binary data? if (gen.canWriteBinaryNatively()) { /* 07-Dec-2013, tatu: One nasty case; that of TokenBuffer. While it can * technically retain binary data, we do not want to do use binary * with it, as that results in UUIDs getting converted to Base64 for * most conversions. */ if (!(gen instanceof TokenBuffer)) { gen.writeBinary(_asBytes(value)); return; } } // UUID.toString() works ok functionally, but we can make it go much faster // (by 4x with micro-benchmark) final char[] ch = new char[36]; final long msb = value.getMostSignificantBits(); _appendInt((int) (msb >> 32), ch, 0); ch[8] = '-'; int i = (int) msb; _appendShort(i >>> 16, ch, 9); ch[13] = '-'; _appendShort(i, ch, 14); ch[18] = '-'; final long lsb = value.getLeastSignificantBits(); _appendShort((int) (lsb >>> 48), ch, 19); ch[23] = '-'; _appendShort((int) (lsb >>> 32), ch, 24); _appendInt((int) lsb, ch, 28); gen.writeString(ch, 0, 36); }
Example 5
Source File: ServletResponseResultWriter.java From endpoints-java with Apache License 2.0 | 5 votes |
private static SimpleModule getWriteBlobAsBase64Module() { JsonSerializer<Blob> dateSerializer = new JsonSerializer<Blob>() { @Override public void serialize(Blob value, JsonGenerator jgen, SerializerProvider provider) throws IOException { byte[] bytes = value.getBytes(); jgen.writeBinary(bytes, 0, bytes.length); } }; SimpleModule writeBlobAsBase64Module = new SimpleModule("writeBlobAsBase64Module", new Version(1, 0, 0, null, null, null)); writeBlobAsBase64Module.addSerializer(Blob.class, dateSerializer); return writeBlobAsBase64Module; }
Example 6
Source File: X509CertificateSerializer.java From webauthn4j with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void serialize(X509Certificate value, JsonGenerator gen, SerializerProvider provider) throws IOException { try { gen.writeBinary(value.getEncoded()); } catch (CertificateEncodingException e) { throw new UnexpectedCheckedException(e); } }
Example 7
Source File: ByteArraySerializer.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void serialize(byte[] value, JsonGenerator g, SerializerProvider provider) throws IOException { g.writeBinary(provider.getConfig().getBase64Variant(), value, 0, value.length); }
Example 8
Source File: RangeBoundValueSerializer.java From presto-kudu with Apache License 2.0 | 5 votes |
private void writeValue(Object obj, JsonGenerator gen) throws IOException { if (obj == null) { throw new IllegalStateException("Unexpected null value"); } else if (obj instanceof String) { gen.writeString((String) obj); } else if (Number.class.isAssignableFrom(obj.getClass())) { if (obj instanceof Long) { gen.writeNumber((Long) obj); } else if (obj instanceof Integer) { gen.writeNumber((Integer) obj); } else if (obj instanceof Short) { gen.writeNumber((Short) obj); } else if (obj instanceof Double) { gen.writeNumber((Double) obj); } else if (obj instanceof Float) { gen.writeNumber((Float) obj); } else if (obj instanceof BigInteger) { gen.writeNumber((BigInteger) obj); } else if (obj instanceof BigDecimal) { gen.writeNumber((BigDecimal) obj); } else { throw new IllegalStateException("Unknown number value: " + obj); } } else if (obj instanceof Boolean) { gen.writeBoolean((Boolean) obj); } else if (obj instanceof byte[]) { gen.writeBinary((byte[]) obj); } }
Example 9
Source File: SchemaSerDe.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
@Override protected void doSerialize(Schema schema, JsonGenerator jgen, SerializerProvider provider) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); MessageSerializer.serialize(new WriteChannel(Channels.newChannel(out)), schema); jgen.writeBinary(out.toByteArray()); }
Example 10
Source File: ArrowRecordBatchSerDe.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
@Override protected void doSerialize(ArrowRecordBatch arrowRecordBatch, JsonGenerator jgen, SerializerProvider provider) throws IOException { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); MessageSerializer.serialize(new WriteChannel(Channels.newChannel(out)), arrowRecordBatch); jgen.writeBinary(out.toByteArray()); } finally { arrowRecordBatch.close(); } }
Example 11
Source File: FileChunksMeta.java From WeEvent with Apache License 2.0 | 4 votes |
@Override public void serialize(BitSet value, JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeBinary(value.toByteArray()); }
Example 12
Source File: DoubleHistogramSerializer.java From SkaETL with Apache License 2.0 | 4 votes |
@Override public void serialize(DoubleHistogram doubleHistogram, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { ByteBuffer allocate = ByteBuffer.allocate(doubleHistogram.getNeededByteBufferCapacity()); doubleHistogram.encodeIntoByteBuffer(allocate); jsonGenerator.writeBinary(allocate.array()); }
Example 13
Source File: ProtoSerializers.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public void serialize(X value, JsonGenerator gen, SerializerProvider provider) throws IOException { gen.writeBinary(ProtostuffIOUtil.toByteArray(value, schema, LinkedBuffer.allocate())); // JsonIOUtil.writeTo(gen, value, schema, false); }
Example 14
Source File: CompleteType.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public void serialize(CompleteType value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeBinary(value.serialize()); }
Example 15
Source File: JWSSerializer.java From webauthn4j with Apache License 2.0 | 4 votes |
@Override public void serialize(JWS<? extends Serializable> value, JsonGenerator gen, SerializerProvider provider) throws IOException { gen.writeBinary(value.getBytes()); }
Example 16
Source File: AAGUIDSerializer.java From webauthn4j with Apache License 2.0 | 4 votes |
@Override public void serialize(AAGUID value, JsonGenerator gen, SerializerProvider provider) throws IOException { gen.writeBinary(value.getBytes()); }
Example 17
Source File: TPMSAttestSerializer.java From webauthn4j with Apache License 2.0 | 4 votes |
@Override public void serialize(TPMSAttest value, JsonGenerator gen, SerializerProvider provider) throws IOException { gen.writeBinary(value.getBytes()); }
Example 18
Source File: PhysicalPlanReader.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public void serialize(ByteString value, JsonGenerator gen, SerializerProvider provider) throws IOException { gen.writeBinary(value.toByteArray()); }
Example 19
Source File: StoneSerializers.java From dropbox-sdk-java with MIT License | 4 votes |
@Override public void serialize(byte [] value, JsonGenerator g) throws IOException, JsonGenerationException { g.writeBinary(value); }
Example 20
Source File: ByteBufSerializer.java From log4j2-elasticsearch with Apache License 2.0 | 3 votes |
@Override public void serialize(ByteBuf byteBuf, JsonGenerator gen, SerializerProvider serializers) throws IOException { byteBuf.resetReaderIndex(); ByteBufInputStream inputStream = new ByteBufInputStream(byteBuf); gen.writeBinary(inputStream, byteBuf.writerIndex()); }