Package org.nustaq.kson
Class Kson
java.lang.Object
org.nustaq.kson.Kson
public class Kson extends Object
a simple text <=> object serialization. More readable than JSon, less complication/error prone than Yaml.
Main use is configuration files. - Supports Pojo's only. - No multidimensional or nested arrays. - No untyped Arrays (e.g. Object x[] = new byte[] { 1, 2}) - Collections: Map and List. Use Generics to type collections (can omit type tags then) Example from fast-cast:
public static ClusterConf readFrom( String filePath ) throws Exception {
return (ClusterConf) new Kson()
.map(PublisherConf.class, SubscriberConf.class, TopicConf.class, ClusterConf.class)
.readObject(new File(filePath));
}
-
Field Summary
Fields Modifier and Type Field Description static FSTConfigurationconf -
Constructor Summary
Constructors Constructor Description Kson()Kson(KsonTypeMapper mapper) -
Method Summary
Modifier and Type Method Description static ClassfumbleOutGenericKeyType(Field field)static ClassfumbleOutGenericValueType(Field field)KsonTypeMappergetMapper()booleanisSupportJSon()static voidmain(String[] args)Ksonmap(Class... c)map to simple nameKsonmap(String name, Class c)ObjectreadObject(File file)ObjectreadObject(File file, Class type)ObjectreadObject(File file, String type)ObjectreadObject(InputStream stream, String encoding, String expectedType)ObjectreadObject(String dson)ObjectreadObject(String dsonOrJSon, String expectedType)ObjectreadObject(String dsonOrJSon, String expectedType, KsonArgTypesResolver resolve)KsonsupportJSon(boolean supportJSon)StringwriteJSonObject(Object o, boolean tagTopLevel)StringwriteObject(Object o)StringwriteObject(Object o, boolean tagTopLevel)StringwritePlainJSonObject(Object o)
-
Field Details
-
Constructor Details
-
Method Details
-
fumbleOutGenericKeyType
-
fumbleOutGenericValueType
-
map
-
map
map to simple name- Parameters:
c-- Returns:
-
readObject
- Throws:
Exception
-
readObject
public Object readObject(String dsonOrJSon, String expectedType, KsonArgTypesResolver resolve) throws Exception- Throws:
Exception
-
readObject
- Throws:
Exception
-
isSupportJSon
public boolean isSupportJSon() -
supportJSon
-
readObject
- Throws:
Exception
-
readObject
- Throws:
Exception
-
readObject
- Throws:
Exception
-
readObject
public Object readObject(InputStream stream, String encoding, String expectedType) throws Exception- Throws:
Exception
-
writeObject
- Throws:
Exception
-
writeObject
- Throws:
Exception
-
writeJSonObject
- Throws:
Exception
-
writePlainJSonObject
- Throws:
Exception
-
getMapper
-
main
- Throws:
Exception
-