Skip to content

Commit

Permalink
WICKET-6287 Switch from json.org to open-json
Browse files Browse the repository at this point in the history
  • Loading branch information
bitstorm committed Jan 4, 2017
1 parent cfa34e6 commit f8a6afd
Show file tree
Hide file tree
Showing 49 changed files with 211 additions and 232 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.wicketstuff.datatables.demo.infiniteScroll;

import org.apache.wicket.ajax.json.JSONObject;
import org.json.JSONObject;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.wicketstuff.datatables.demo.PeopleDataProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.wicketstuff.datatables.virtualscroll;

import org.apache.wicket.ajax.json.JSONArray;
import org.apache.wicket.ajax.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.request.mapper.parameter.PageParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.net.URL;
import java.net.URLEncoder;

import org.apache.wicket.ajax.json.JSONException;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wicketstuff.gmap.GMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import org.apache.wicket.Page;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.ajax.json.JSONArray;
import org.apache.wicket.ajax.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import org.apache.wicket.markup.head.HeaderItem;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.request.IRequestHandler;
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,12 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>de.agilecoders.wicket</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.apache.wicket.Component;
import org.apache.wicket.IRequestListener;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONWriter;
import org.apache.wicket.event.IEvent;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
Expand All @@ -40,6 +38,8 @@
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.util.string.AppendingStringBuffer;
import org.apache.wicket.util.string.Strings;
import org.json.JSONException;
import org.json.JSONStringer;

/**
* Base class for Select2 components
Expand Down Expand Up @@ -369,7 +369,7 @@ public static <T> void generateJSON(String queryParam, ChoiceProvider<T> provide
// jsonize and write out the choices to the response

OutputStreamWriter out = new OutputStreamWriter(outputStream, request.getCharset());
JSONWriter json = new JSONWriter(out);
JSONStringer json = new JSONStringer();

try
{
Expand All @@ -383,8 +383,10 @@ public static <T> void generateJSON(String queryParam, ChoiceProvider<T> provide
}
json.endArray();
json.key("more").value(response.getHasMore()).endObject();

out.write(json.toString());
}
catch (JSONException e)
catch (JSONException | IOException e)
{
throw new RuntimeException("Could not write Json response", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import java.io.Serializable;

import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONWriter;
import org.json.JSONException;
import org.json.JSONStringer;
import org.wicketstuff.select2.json.Json;

/**
Expand All @@ -34,16 +34,16 @@ public final class AjaxSettings implements Serializable
/** whether or not to use traditional parameter encoding. */
private boolean cache;

public void toJson(JSONWriter writer) throws JSONException
public void toJson(JSONStringer stringer) throws JSONException
{
writer.object();
Json.writeFunction(writer, "data", data);
Json.writeObject(writer, "dataType", dataType);
Json.writeObject(writer, "delay", delay);
Json.writeFunction(writer, "processResults", processResults);
Json.writeObject(writer, "url", url);
Json.writeObject(writer, "cache", cache);
writer.endObject();
stringer.object();
Json.writeFunction(stringer, "data", data);
Json.writeObject(stringer, "dataType", dataType);
Json.writeObject(stringer, "delay", delay);
Json.writeFunction(stringer, "processResults", processResults);
Json.writeObject(stringer, "url", url);
Json.writeObject(stringer, "cache", cache);
stringer.endObject();
}

public void setUrl(CharSequence url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import java.util.Collection;

import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONWriter;
import org.apache.wicket.model.IDetachable;
import org.json.JSONException;
import org.json.JSONStringer;

/**
* <p>
Expand Down Expand Up @@ -105,12 +105,12 @@ public abstract class ChoiceProvider<T> implements IDetachable
*
* @param choice
* choice to convert
* @param writer
* @param stringer
* Json writer that should be used to covnert the choice
* @throws JSONException
*/
protected void toJson(T choice, JSONWriter writer) throws JSONException {
writer.key("id").value(getIdValue(choice)).key("text").value(getDisplayValue(choice));
protected void toJson(T choice, JSONStringer stringer) throws JSONException {
stringer.key("id").value(getIdValue(choice)).key("text").value(getDisplayValue(choice));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
*/
package org.wicketstuff.select2;

import static org.apache.wicket.util.string.Strings.defaultIfEmpty;

import java.io.Serializable;

import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONStringer;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.util.string.Strings;
import org.json.JSONException;
import org.json.JSONStringer;
import org.wicketstuff.select2.json.Json;

import static org.apache.wicket.util.string.Strings.defaultIfEmpty;

/**
* Select2 settings. Refer to the Select2 documentation for what these options mean.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
*/
package org.wicketstuff.select2.json;

import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONWriter;
import org.apache.wicket.ajax.json.JSONFunction;
import org.json.JSONException;
import org.json.JSONStringer;

/**
* Json utilities
Expand All @@ -27,42 +28,42 @@ private Json()
/**
* Writes a key/value pair into the {@code writer} if the value is not {@code null}
*
* @param writer
* @param stringer
* json writer
* @param key
* key
* @param value
* value
* @throws JSONException
*/
public static void writeObject(JSONWriter writer, String key, Object value)
public static void writeObject(JSONStringer stringer, String key, Object value)
throws JSONException
{
if (value != null)
{
writer.key(key);
writer.value(value);
stringer.key(key);
stringer.value(value);
}
}

/**
* Writes a key/value pair into the {@code writer} where {@code value} represents a javascript
* function and should be written out unencoded if the value is not {@code null}
*
* @param writer
* @param stringer
* json writer
* @param key
* key
* @param value
* value
* @throws JSONException
*/
public static void writeFunction(JSONWriter writer, String key, String value)
public static void writeFunction(JSONStringer stringer, String key, String value)
throws JSONException
{
if (value != null)
{
writer.key(key).value(new JsonFunction(value));
stringer.key(key).value(new JSONFunction(value));
}
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;

import org.apache.wicket.ajax.json.JSONArray;
import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONObject;
import org.apache.wicket.ajax.json.JSONTokener;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import java.util.Set;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import org.apache.wicket.ajax.json.JSONArray;
import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONObject;
import org.apache.wicket.ajax.json.JSONTokener;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONStringer;
import org.apache.wicket.ajax.json.JSONWriter;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.head.HeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
Expand All @@ -32,6 +29,8 @@
import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.json.JSONException;
import org.json.JSONStringer;

/**
* Reads URL fragment parameters. This {@link Behavior} will execute an AJAX call to itself with the
Expand Down Expand Up @@ -98,7 +97,7 @@ private String optionsJsonString()
String optionsJsonString = "";
try
{
JSONWriter writer = new JSONStringer().object();
JSONStringer writer = new JSONStringer().object();
for (String key : options.keySet())
{
writer.key(key).value(options.get(key));
Expand Down
Loading

0 comments on commit f8a6afd

Please sign in to comment.