aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/json/JSONSerializer.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-07 11:32:44 +0300
committerGravatar Vitaly Takmazov2016-07-07 11:32:44 +0300
commitfe8cf8c0093bbbfb053f52a53daea9145705b62e (patch)
tree3515f5d254016f73287696e2a08ba6e7fd824714 /src/main/java/com/juick/json/JSONSerializer.java
parenta8b38ca23e9b43527e85b0dbf5c9267401fd3c69 (diff)
parentfc46d9c1f8c9967f9c648f09a3714e8c3a4ed75a (diff)
merge json
Diffstat (limited to 'src/main/java/com/juick/json/JSONSerializer.java')
-rw-r--r--src/main/java/com/juick/json/JSONSerializer.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main/java/com/juick/json/JSONSerializer.java b/src/main/java/com/juick/json/JSONSerializer.java
new file mode 100644
index 00000000..142cacf0
--- /dev/null
+++ b/src/main/java/com/juick/json/JSONSerializer.java
@@ -0,0 +1,54 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.juick.json;
+
+import java.text.ParseException;
+import java.util.Iterator;
+import java.util.List;
+import org.json.JSONObject;
+
+/**
+ *
+ * @author vt
+ * @param <T>
+ */
+public abstract class JSONSerializer<T> {
+
+ /**
+ *
+ * @param json
+ * @return
+ */
+ public abstract T deserialize(JSONObject json) throws ParseException;
+
+ /**
+ *
+ * @param obj
+ * @return
+ */
+ public abstract JSONObject serialize(T obj);
+
+ /**
+ *
+ * @param objs
+ * @return
+ */
+ public String serializeList(List<T> objs) {
+ String json = "[";
+
+ Iterator<T> i = objs.iterator();
+ while (i.hasNext()) {
+ T m = i.next();
+ if (json.length() > 1) {
+ json += ",";
+ }
+ json += serialize(m).toString();
+ }
+
+ json += "]";
+ return json;
+ }
+}