You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2016/11/10 15:14:17 UTC
[45/50] [abbrv] groovy git commit: docs and minor formatting
docs and minor formatting
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/8a4c25c2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8a4c25c2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8a4c25c2
Branch: refs/heads/parrot
Commit: 8a4c25c20d0317933812c6530f54819d7444b537
Parents: 0da0871
Author: John Wagenleitner <jw...@apache.org>
Authored: Tue Nov 8 17:11:02 2016 -0800
Committer: John Wagenleitner <jw...@apache.org>
Committed: Tue Nov 8 17:11:02 2016 -0800
----------------------------------------------------------------------
.../java/groovy/json/DefaultJsonGenerator.java | 17 ++++++++---------
.../src/main/java/groovy/json/JsonGenerator.java | 18 +++++++-----------
.../groovy-json/src/spec/doc/json-userguide.adoc | 8 ++++----
3 files changed, 19 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/8a4c25c2/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java b/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
index 634d9d3..884486d 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/DefaultJsonGenerator.java
@@ -442,18 +442,17 @@ public class DefaultJsonGenerator implements JsonGenerator {
}
/**
- * A converter that handles converting a given type to a JSON value
- * using a closure.
+ * A converter that handles converting a given type using a closure.
*
* @since 2.5
*/
protected static class ClosureConverter implements Converter {
protected final Class<?> type;
- protected final Closure closure;
+ protected final Closure<?> closure;
protected final int paramCount;
- protected ClosureConverter(Class<?> type, Closure closure) {
+ protected ClosureConverter(Class<?> type, Closure<?> closure) {
if (type == null) {
throw new NullPointerException("Type parameter must not be null");
}
@@ -486,28 +485,28 @@ public class DefaultJsonGenerator implements JsonGenerator {
*
* @param type the type of the object to convert
* @return true if this converter can successfully convert values of
- * the given type to a JSON value
+ * the given type
*/
public boolean handles(Class<?> type) {
return this.type.isAssignableFrom(type);
}
/**
- * Converts a given value to a JSON value.
+ * Converts a given value.
*
* @param value the object to convert
- * @return a JSON value representing the value
+ * @return the converted object
*/
public Object convert(Object value) {
return convert(value, null);
}
/**
- * Converts a given value to a JSON value.
+ * Converts a given value.
*
* @param value the object to convert
* @param key the key name for the value, may be {@code null}
- * @return a JSON value representing the value
+ * @return the converted object
*/
public Object convert(Object value, String key) {
return (paramCount == 1) ?
http://git-wip-us.apache.org/repos/asf/groovy/blob/8a4c25c2/subprojects/groovy-json/src/main/java/groovy/json/JsonGenerator.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/JsonGenerator.java b/subprojects/groovy-json/src/main/java/groovy/json/JsonGenerator.java
index e0a13d6..aa81f45 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/JsonGenerator.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/JsonGenerator.java
@@ -67,7 +67,7 @@ public interface JsonGenerator {
boolean isExcludingValues(Object value);
/**
- * Handles converting a given type to a JSON value.
+ * Handles converting a given type.
*
* @since 2.5
*/
@@ -79,24 +79,24 @@ public interface JsonGenerator {
*
* @param type the type of the object to convert
* @return {@code true} if this converter can successfully convert values of
- * the given type to a JSON value, else {@code false}
+ * the given type, else {@code false}
*/
boolean handles(Class<?> type);
/**
- * Converts a given object to a JSON value.
+ * Converts a given object.
*
* @param value the object to convert
- * @return a JSON value representing the object
+ * @return the converted object
*/
Object convert(Object value);
/**
- * Converts a given object to a JSON value.
+ * Converts a given object.
*
* @param value the object to convert
* @param key the key name for the value, may be {@code null}
- * @return a JSON value representing the object
+ * @return the converted object
*/
Object convert(Object value, String key);
@@ -216,10 +216,6 @@ public interface JsonGenerator {
* value if serializing a JSON Object. This parameter will be {@code null} when
* serializing a JSON Array or when there is no way to determine the name of the key.
*
- * <p>The return value from the closure must be a valid JSON value. The result
- * of the closure will be written to the internal buffer directly and no quoting,
- * escaping or other manipulation will be done to the resulting output.
- *
* <p>
* Example:
* <pre><code class="groovyTestCase">
@@ -251,7 +247,7 @@ public interface JsonGenerator {
*/
public <T> Options addConverter(Class<T> type,
@ClosureParams(value=FromString.class, options={"T","T,String"})
- Closure closure)
+ Closure<?> closure)
{
Converter converter = new DefaultJsonGenerator.ClosureConverter(type, closure);
if (converters.contains(converter)) {
http://git-wip-us.apache.org/repos/asf/groovy/blob/8a4c25c2/subprojects/groovy-json/src/spec/doc/json-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/spec/doc/json-userguide.adoc b/subprojects/groovy-json/src/spec/doc/json-userguide.adoc
index 683e403..dec466b 100644
--- a/subprojects/groovy-json/src/spec/doc/json-userguide.adoc
+++ b/subprojects/groovy-json/src/spec/doc/json-userguide.adoc
@@ -188,10 +188,10 @@ configured instance that will generate output based on the options selected.
include::{rootProjectDir}/subprojects/groovy-json/src/spec/test/json/JsonTest.groovy[tags=json_output_generator,indent=0]
----
-A closure can be used to transform a type into a valid JSON value. These closure converters are registered
-for a given type and will be called any time that type or a subtype is encountered. The first parameter to the
-closure is an object matching the type for which the converter is registered and this parameter is required.
-The closure may take an optional second `String` parameter and this will be set to the key name if one is available.
+A closure can be used to transform a type. These closure converters are registered for a given type and will be
+called any time that type or a subtype is encountered. The first parameter to the closure is an object matching the
+type for which the converter is registered and this parameter is required. The closure may take an optional second
+`String` parameter and this will be set to the key name if one is available.
[source,groovy]
----