Fixed some warnings and added toString function in JSONObjectStream

This commit is contained in:
Ziver Koc 2017-01-16 17:07:35 +01:00
parent 5c9a064eca
commit 89076bfa54
4 changed files with 20 additions and 4 deletions

0
src/zutil/db/bean/DBBean.java Normal file → Executable file
View file

View file

@ -45,7 +45,7 @@ public class DBBeanSQLResultHandler<T> implements SQLResultHandler<T>{
public static final long CACHE_DATA_TTL = 1000*60*5; // 5 min in ms
/** A cache for detecting recursion **/
protected static Map<Class<?>, Map<Long,DBBeanCache>> cache =
new ConcurrentHashMap<Class<?>, Map<Long,DBBeanCache>>();
new ConcurrentHashMap<>();
private static Timer timer;
static {
@ -283,7 +283,7 @@ public class DBBeanSQLResultHandler<T> implements SQLResultHandler<T>{
} finally{
obj.processing_update = false;
}
obj.postUpdateAction();
}

View file

@ -25,6 +25,7 @@
package zutil.parser.json;
import zutil.ClassUtil;
import zutil.io.StringOutputStream;
import zutil.parser.Base64Encoder;
import zutil.parser.DataNode;
import zutil.parser.DataNode.DataType;
@ -52,7 +53,7 @@ public class JSONObjectOutputStream extends OutputStream implements ObjectOutput
private JSONWriter out;
private JSONObjectOutputStream() {
this.objectCache = new HashMap<Object, Integer>();
this.objectCache = new HashMap<>();
}
public JSONObjectOutputStream(OutputStream out) {
this();
@ -64,6 +65,21 @@ public class JSONObjectOutputStream extends OutputStream implements ObjectOutput
}
/**
* @return a String containing the JSON representation of the Object
*/
public static String toString(Object obj){
try {
StringOutputStream out = new StringOutputStream();
JSONObjectOutputStream writer = new JSONObjectOutputStream(out);
writer.writeObject(obj);
writer.close();
return out.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public synchronized void writeObject(Object obj) throws IOException{
try{

View file

@ -132,7 +132,7 @@ public class JSONWriter{
}
/**
* @return JSON String that is generated from the input DataNode graph
* @return a String containing the JSON representation of the input DataNode graph
*/
public static String toString(DataNode root){
StringOutputStream out = new StringOutputStream();