Package groovy.json
Class DefaultJsonGenerator.ClosureConverter
java.lang.Object
groovy.json.DefaultJsonGenerator.ClosureConverter
- All Implemented Interfaces:
JsonGenerator.Converter
- Enclosing class:
- DefaultJsonGenerator
protected static class DefaultJsonGenerator.ClosureConverter extends Object implements JsonGenerator.Converter
A converter that handles converting a given type using a closure.
- Since:
- 2.5.0
-
Field Summary
Fields Modifier and Type Field Description protected Closure<?>
closure
protected int
paramCount
protected Class<?>
type
-
Constructor Summary
Constructors Modifier Constructor Description protected
ClosureConverter(Class<?> type, Closure<?> closure)
-
Method Summary
Modifier and Type Method Description Object
convert(Object value, String key)
Converts a given value.boolean
equals(Object o)
Any two Converter instances registered for the same type are considered to be equal.boolean
handles(Class<?> type)
Returnstrue
if this converter can handle conversions of the given type.int
hashCode()
String
toString()
-
Field Details
-
type
-
closure
-
paramCount
protected final int paramCount
-
-
Constructor Details
-
ClosureConverter
-
-
Method Details
-
handles
Returnstrue
if this converter can handle conversions of the given type.- Specified by:
handles
in interfaceJsonGenerator.Converter
- Parameters:
type
- the type of the object to convert- Returns:
- true if this converter can successfully convert values of the given type
-
convert
Converts a given value.- Specified by:
convert
in interfaceJsonGenerator.Converter
- Parameters:
value
- the object to convertkey
- the key name for the value, may benull
- Returns:
- the converted object
-
equals
Any two Converter instances registered for the same type are considered to be equal. This comparison makes managing instances in a Set easier; since there is no chaining of Converters it makes sense to only allow one per type. -
hashCode
public int hashCode() -
toString
-