Skip to content

Commit

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

import org.json.JSONObject;
import org.apache.wicket.ajax.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.json.JSONArray;
import org.json.JSONObject;
import org.apache.wicket.ajax.json.JSONArray;
import org.apache.wicket.ajax.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.json.JSONException;
import org.apache.wicket.ajax.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.json.JSONArray;
import org.json.JSONObject;
import org.apache.wicket.ajax.json.JSONArray;
import org.apache.wicket.ajax.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: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.5</version>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>de.agilecoders.wicket</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
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 @@ -38,8 +40,6 @@
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());
JSONStringer json = new JSONStringer();
JSONWriter json = new JSONWriter(out);

try
{
Expand All @@ -383,10 +383,8 @@ 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 | IOException e)
catch (JSONException 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.json.JSONException;
import org.json.JSONStringer;
import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONWriter;
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(JSONStringer stringer) throws JSONException
public void toJson(JSONWriter writer) throws JSONException
{
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();
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();
}

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 stringer
* @param writer
* Json writer that should be used to covnert the choice
* @throws JSONException
*/
protected void toJson(T choice, JSONStringer stringer) throws JSONException {
stringer.key("id").value(getIdValue(choice)).key("text").value(getDisplayValue(choice));
protected void toJson(T choice, JSONWriter writer) throws JSONException {
writer.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,9 +12,8 @@
*/
package org.wicketstuff.select2.json;

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2012 Igor Vaynberg
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with
* the License. You may obtain a copy of the License in the LICENSE file, or at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.wicketstuff.select2.json;

import org.apache.wicket.ajax.json.JSONWriter;

/**
* A JSONWriter that writes and allows access to the underlying {@link StringBuilder}. One of the
* advantages of this class is that it can expose Json as a {@link CharSequence} instead of a
* {@link String} so no extra memory allocations are necessary for code that can use a
* {@link CharSequence} .
*
* @author igor
*
*/
public class JsonBuilder extends JSONWriter
{

/**
* Constructs a builder with a new {@link StringBuilder}.
*/
public JsonBuilder()
{
this(new StringBuilder());
}

/**
* Constructs a builder with an existing {@link StringBuilder}.
*
* @param builder
*/
public JsonBuilder(StringBuilder builder)
{
super(new StringBuilderWriter(builder));
}

/**
* @return underlying {@link StringBuilder} as a {@link CharSequence}.
*/
public CharSequence toJson()
{
return ((StringBuilderWriter)writer).getBuilder();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2012 Igor Vaynberg
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with
* the License. You may obtain a copy of the License in the LICENSE file, or at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.wicketstuff.select2.json;

import org.apache.wicket.ajax.json.JSONString;

/**
* Represents a Json function. When written out these values are not escaped so its possible to
* write out raw JavaScript.
*/
public class JsonFunction implements JSONString
{
private final String value;

public JsonFunction(String value)
{
this.value = value;
}

@Override
public String toJSONString()
{
return value;
}

}
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.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
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.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.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
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.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,6 +21,9 @@
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 @@ -29,8 +32,6 @@
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 @@ -97,7 +98,7 @@ private String optionsJsonString()
String optionsJsonString = "";
try
{
JSONStringer writer = new JSONStringer().object();
JSONWriter writer = new JSONStringer().object();
for (String key : options.keySet())
{
writer.key(key).value(options.get(key));
Expand Down
Loading

0 comments on commit 3f2a87f

Please sign in to comment.