public class JsonEncoder
extends org.apache.avro.io.ParsingEncoder
implements org.apache.avro.io.parsing.Parser.ActionHandler
Encoder for Avro's JSON data encoding.
NOTE: This class is a copy of Avro's JsonEncoder class, with the only difference being that
this class does not wrap union types in JSON by overriding writeIndex(int).
By default, Avro's JSON encoding for union types is to wrap the union value in a JSON object with the type name as the key (e.g., {"string": "value"}). This encoder overrides that behavior to write just the value, resulting in cleaner JSON output.
For instance, a union with schema ["null", "string"] would be encoded as just "value" instead of {"string": "value"}.
This encoder is particularly useful when the standard Avro JSON format's verbosity for union types is not desired.
| Modifier and Type | Field and Description |
|---|---|
protected BitSet |
isEmpty
Has anything been written into the collections?
|
| Constructor and Description |
|---|
JsonEncoder(org.apache.avro.Schema sc,
OutputStream out) |
| Modifier and Type | Method and Description |
|---|---|
JsonEncoder |
configure(OutputStream out)
Reconfigures this JsonEncoder to use the output stream provided.
|
JsonEncoder |
configure(OutputStream out,
boolean autoflush)
Reconfigures this JsonEncoder to use the output stream provided.
|
org.apache.avro.io.parsing.Symbol |
doAction(org.apache.avro.io.parsing.Symbol input,
org.apache.avro.io.parsing.Symbol top) |
void |
flush() |
boolean |
isIncludeNamespace() |
void |
setIncludeNamespace(boolean includeNamespace) |
void |
startItem() |
void |
writeArrayEnd() |
void |
writeArrayStart() |
void |
writeBoolean(boolean b) |
void |
writeBytes(byte[] bytes,
int start,
int len) |
void |
writeBytes(ByteBuffer bytes) |
void |
writeDouble(double d) |
void |
writeEnum(int e) |
void |
writeFixed(byte[] bytes,
int start,
int len) |
void |
writeFloat(float f) |
void |
writeIndex(int unionIndex) |
void |
writeInt(int n) |
void |
writeLong(long n) |
void |
writeMapEnd() |
void |
writeMapStart() |
void |
writeNull() |
void |
writeString(String str) |
void |
writeString(org.apache.avro.util.Utf8 utf8) |
protected BitSet isEmpty
public JsonEncoder(org.apache.avro.Schema sc,
OutputStream out)
throws IOException
IOExceptionpublic void flush()
throws IOException
flush in interface FlushableIOExceptionpublic boolean isIncludeNamespace()
public void setIncludeNamespace(boolean includeNamespace)
public JsonEncoder configure(OutputStream out) throws IOException
out - The OutputStream to direct output to. Cannot be null.IOExceptionNullPointerException - if out is nullpublic JsonEncoder configure(OutputStream out, boolean autoflush) throws IOException
out - The OutputStream to direct output to. Cannot be null.IOExceptionNullPointerException - if out is nullpublic void writeNull()
throws IOException
writeNull in class org.apache.avro.io.EncoderIOExceptionpublic void writeBoolean(boolean b)
throws IOException
writeBoolean in class org.apache.avro.io.EncoderIOExceptionpublic void writeInt(int n)
throws IOException
writeInt in class org.apache.avro.io.EncoderIOExceptionpublic void writeLong(long n)
throws IOException
writeLong in class org.apache.avro.io.EncoderIOExceptionpublic void writeFloat(float f)
throws IOException
writeFloat in class org.apache.avro.io.EncoderIOExceptionpublic void writeDouble(double d)
throws IOException
writeDouble in class org.apache.avro.io.EncoderIOExceptionpublic void writeString(org.apache.avro.util.Utf8 utf8)
throws IOException
writeString in class org.apache.avro.io.EncoderIOExceptionpublic void writeString(String str) throws IOException
writeString in class org.apache.avro.io.EncoderIOExceptionpublic void writeBytes(ByteBuffer bytes) throws IOException
writeBytes in class org.apache.avro.io.EncoderIOExceptionpublic void writeBytes(byte[] bytes,
int start,
int len)
throws IOException
writeBytes in class org.apache.avro.io.EncoderIOExceptionpublic void writeFixed(byte[] bytes,
int start,
int len)
throws IOException
writeFixed in class org.apache.avro.io.EncoderIOExceptionpublic void writeEnum(int e)
throws IOException
writeEnum in class org.apache.avro.io.EncoderIOExceptionpublic void writeArrayStart()
throws IOException
writeArrayStart in class org.apache.avro.io.EncoderIOExceptionpublic void writeArrayEnd()
throws IOException
writeArrayEnd in class org.apache.avro.io.EncoderIOExceptionpublic void writeMapStart()
throws IOException
writeMapStart in class org.apache.avro.io.EncoderIOExceptionpublic void writeMapEnd()
throws IOException
writeMapEnd in class org.apache.avro.io.EncoderIOExceptionpublic void startItem()
throws IOException
startItem in class org.apache.avro.io.ParsingEncoderIOExceptionpublic void writeIndex(int unionIndex)
throws IOException
writeIndex in class org.apache.avro.io.EncoderIOExceptionpublic org.apache.avro.io.parsing.Symbol doAction(org.apache.avro.io.parsing.Symbol input,
org.apache.avro.io.parsing.Symbol top)
throws IOException
doAction in interface org.apache.avro.io.parsing.Parser.ActionHandlerIOExceptionCopyright © 2024 The Apache Software Foundation. All rights reserved.