diff options
author | Vitaly Takmazov | 2016-11-28 14:37:02 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-28 14:37:02 +0300 |
commit | 5b2bd7f928bbf9d3233ff029ed5c09ac46daf0de (patch) | |
tree | cfad7f15e35c51d11a488df5a9b2be5300b9af54 /src/test/java/com/juick/json/JSONSerializer.java | |
parent | c252087c54e91e63f89775eba4c65cf87ae21e5d (diff) |
all components using jackson now, org.json serializer moved to compatibility tests package
Diffstat (limited to 'src/test/java/com/juick/json/JSONSerializer.java')
-rw-r--r-- | src/test/java/com/juick/json/JSONSerializer.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/test/java/com/juick/json/JSONSerializer.java b/src/test/java/com/juick/json/JSONSerializer.java new file mode 100644 index 00000000..3dc9e04e --- /dev/null +++ b/src/test/java/com/juick/json/JSONSerializer.java @@ -0,0 +1,73 @@ +/* + * 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> { + + public enum URIScheme { + Plain, + Secure + } + + private URIScheme uriScheme; + + public URIScheme getUriScheme() { + return uriScheme; + } + + public void setUriScheme(URIScheme uriScheme) { + this.uriScheme = uriScheme; + } + + public JSONSerializer() { + this.uriScheme = URIScheme.Plain; + } + + /** + * + * @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; + } +} |