|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.qtunes.core.util.JSONSerializer
public class JSONSerializer
Class to read/write objects as JSON.
Can be overridden to support custom serialization. For writing this should involve
overriding the getCustomWrite(java.lang.Object) method like so:
public Object getCustomWrite(Object o) {
if (o instanceof Widget) {
Map m = new HashMap();
m.put("type", "widget");
m.put("name", widget.getName());
return m;
} else {
return super.getCustomWrite(o);
}
}
and for reading the getCustomRead(java.util.Map) methods:
public Object getCustomRead(Map m) {
if ("widget".equals(m.get("type"))) {
return Widget.getByName((String)m.get("name"));
} else {
return super.getCustomRead();
}
}
| Constructor Summary | |
|---|---|
JSONSerializer()
|
|
| Method Summary | |
|---|---|
protected java.lang.Object |
getCustomRead(java.util.List list)
Subclasses may override this method to return a more specific type of object than the List specified. |
protected java.lang.Object |
getCustomRead(java.util.Map map)
Subclasses may override this method to return a more specific type of object than the Map specified. |
java.lang.Object |
getCustomWrite(java.lang.Object object)
Get an object that can be serialized to represent the specified Object. |
java.lang.Object |
read(java.io.Reader reader)
Parse a JSON serialized object from the Reader and return the Object it represents |
java.lang.Object |
read(java.lang.String s)
Parse a JSON serialized String and return the Object it represents |
java.lang.Object |
readAsProbableString(java.lang.String s)
|
protected java.lang.Object |
readCustomToken(int c,
java.io.Reader reader)
|
void |
setLaxKeyQuoting(boolean lax)
|
java.lang.String |
write(java.lang.Object object)
Serialize the object and return the serialized version as a String |
void |
write(java.lang.Object o,
java.lang.Appendable sb)
Serialize the object and write the serialized version to the specified Appendable |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JSONSerializer()
| Method Detail |
|---|
public void setLaxKeyQuoting(boolean lax)
public java.lang.String write(java.lang.Object object)
object - the Object to serialize
public void write(java.lang.Object o,
java.lang.Appendable sb)
throws java.io.IOException
Appendable
o - the Object to serialize
java.io.IOException
public java.lang.Object getCustomWrite(java.lang.Object object)
throws java.lang.IllegalArgumentException
object - an unserializable Object
java.lang.IllegalArgumentException
public java.lang.Object readAsProbableString(java.lang.String s)
throws java.io.IOException
java.io.IOException
public java.lang.Object read(java.lang.String s)
throws java.io.IOException
java.io.IOException
public java.lang.Object read(java.io.Reader reader)
throws java.io.IOException
java.io.IOExceptionprotected java.lang.Object getCustomRead(java.util.Map map)
getCustomWrite(java.lang.Object).
map - a generic Map
protected java.lang.Object getCustomRead(java.util.List list)
getCustomWrite(java.lang.Object).
list - a generic List
protected java.lang.Object readCustomToken(int c,
java.io.Reader reader)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||