|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectaQute.lib.json.JSONCodec
public class JSONCodec
This is a simple JSON Coder and Encoder that uses the Java type system to convert data objects to JSON and JSON to (type safe) Java objects. The conversion is very much driven by classes and their public fields. Generic information, when present is taken into account.
Usage patterns to encode:
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
| Constructor Summary | |
|---|---|
JSONCodec()
|
|
| Method Summary | |
|---|---|
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()
|
JSONCodec |
setIgnorenull(boolean ignorenull)
Ignore null values in output and input |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JSONCodec()
| Method Detail |
|---|
public Encoder enc()
public Decoder dec()
public JSONCodec setIgnorenull(boolean ignorenull)
ignorenull -
public boolean isIgnorenull()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||