public class JSONCodec
extends java.lang.Object
JSONCoder codec = new JSONCodec(); // assert "1".equals(
codec.enc().to().put(1).toString()); assert "[1,2,3]".equals(
codec.enc().to().put(Arrays.asList(1,2,3).toString()); Map m = new HashMap();
m.put("a", "A"); assert "{\"a\":\"A\"}".equals(
codec.enc().to().put(m).toString()); static class D { public int a; } D d =
new D(); d.a = 41; assert "{\"a\":41}".equals(
codec.enc().to().put(d).toString());
It is possible to redirect the encoder to another output (default is a
string). See Encoder.to(),Encoder.to(File),
Encoder.to(OutputStream), Encoder.to(Appendable). To reset
the string output call Encoder.to().
This Codec class can be used in a concurrent environment. The Decoders and
Encoders, however, must only be used in a single thread.
Will now use hex for encoding byte arrays| Modifier and Type | Field and Description |
|---|---|
protected static char[] |
hexArray |
| Constructor and Description |
|---|
JSONCodec() |
| Modifier and Type | Method and Description |
|---|---|
JSONCodec |
addHandler(java.lang.reflect.Type type,
Handler handler)
Add a new local handler
|
<T> void |
addNumberHandler(java.lang.Class<T> type,
java.util.function.Function<T,java.lang.Number> toNumber,
java.util.function.Function<java.lang.Number,T> fromNumber) |
<T> void |
addStringHandler(java.lang.Class<T> type,
java.util.function.Function<T,java.lang.String> toString,
java.util.function.Function<java.lang.String,T> fromString) |
JSONCodec |
base64() |
static java.lang.String |
bytesToHex(byte[] bytes) |
Decoder |
dec()
Create a new Decoder with the state and appropriate API.
|
Encoder |
enc()
Create a new Encoder with the state and appropriate API.
|
boolean |
isIgnorenull() |
static void |
log(java.lang.String format,
java.lang.Object[] args) |
JSONCodec |
nolog() |
JSONCodec |
setIgnorenull(boolean ignorenull)
Ignore null values in output and input
|
void |
setRename(java.util.function.Function<java.lang.reflect.Field,java.lang.String> renamer) |
public Encoder enc()
public Decoder dec()
public JSONCodec setIgnorenull(boolean ignorenull)
ignorenull - public boolean isIgnorenull()
public JSONCodec addHandler(java.lang.reflect.Type type, Handler handler)
public <T> void addStringHandler(java.lang.Class<T> type,
java.util.function.Function<T,java.lang.String> toString,
java.util.function.Function<java.lang.String,T> fromString)
public <T> void addNumberHandler(java.lang.Class<T> type,
java.util.function.Function<T,java.lang.Number> toNumber,
java.util.function.Function<java.lang.Number,T> fromNumber)
public JSONCodec base64()
public static java.lang.String bytesToHex(byte[] bytes)
public JSONCodec nolog()
public static void log(java.lang.String format,
java.lang.Object[] args)
public void setRename(java.util.function.Function<java.lang.reflect.Field,java.lang.String> renamer)
renamer - aQute SARL