Skip to content
Browse files

switch to crockford json libs, deserialize json on upload

  • Loading branch information...
1 parent 53a94a3 commit 0d0066e3e39a3216e08f2f26f69f715271124f26 @maxogden committed Mar 8, 2011
View
BIN module/MOD-INF/classes/com/maxogden/refine/uploader/Uploader$1.class
Binary file not shown.
View
BIN module/MOD-INF/classes/com/maxogden/refine/uploader/Uploader.class
Binary file not shown.
View
BIN module/MOD-INF/lib/gson-1.6.jar
Binary file not shown.
View
24 src/com/maxogden/refine/uploader/Uploader.java
@@ -12,6 +12,7 @@
import org.json.JSONException;
import org.json.JSONObject;
+import org.json.JSONArray;
import org.json.JSONWriter;
import com.google.refine.commands.Command;
import com.google.refine.ProjectManager;
@@ -23,8 +24,6 @@
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.util.ParsingUtilities;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
@@ -108,7 +107,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
FilteredRows filteredRows = engine.getAllFilteredRows();
filteredRows.accept(project, createRowVisitor(project, values));
- List<HashMap> stuff = new ArrayList<HashMap>();
+ JSONArray stuff = new JSONArray();
for (Column col : project.columnModel.columns) {
columns.add(col.getName());
@@ -117,18 +116,25 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
for (int num = 0; num < values.size(); num++) {
int y = 0;
String[] a = (String[]) values.get(num);
- HashMap rowdata = new HashMap();
+ JSONObject rowdata = new JSONObject();
for (int x = 0; x < a.length; x++) {
- rowdata.put(columns.get(x), a[x]);
+ if(a[x] instanceof String) {
+ if(a[x].contains("{\\\"")) {
+ JSONObject j;
+ j = new JSONObject(a[x].replace("\\\"", "\""));
+ rowdata.put(columns.get(x), j);
+ } else {
+ rowdata.put(columns.get(x), a[x]);
+ }
+ }
y++;
}
- stuff.add(rowdata);
+ stuff.put(rowdata);
}
- HashMap bulkwrapper = new HashMap();
+ JSONObject bulkwrapper = new JSONObject();
bulkwrapper.put("docs", stuff);
- Gson gson = new Gson();
- String jsondata = gson.toJson(bulkwrapper);
+ String jsondata = bulkwrapper.toString();
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(request.getParameter("url"));
StringEntity se = new StringEntity(jsondata);

0 comments on commit 0d0066e

Please sign in to comment.
Something went wrong with that request. Please try again.