Package: groovy.json

## [Java] Class DefaultJsonGenerator.ClosureConverter

- groovy.json.DefaultJsonGenerator.ClosureConverter

- All Implemented Interfaces and Traits:
    Converter

      protected static class DefaultJsonGenerator.ClosureConverter
      extends Object
      implements Converter

  A converter that handles converting a given type using a closure.

  Since:
    2.5.0

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected Closure<?>` | `closure` |
    `protected int` | `paramCount` |
    `protected Class<?>` | `type` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `protected ClosureConverter(Class<?> type, Closure<?> closure)`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Object` | `convert(Object value, String key)` Converts a given value.
    `` | `public boolean` | `equals(Object o)` Any two Converter instances registered for the same type are considered to be equal.
    `` | `public boolean` | `handles(Class<?> type)` Returns `true` if this converter can handle conversions of the given type.
    `` | `public int` | `hashCode()`
    `` | `public String` | `toString()`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### protected final Closure<?> closure

    - #### protected final int paramCount

    - #### protected final Class<?> type

  - ### Constructor Detail

    - #### protected ClosureConverter(Class<?> type, Closure<?> closure)

  - ### Method Detail

    - #### @Override
      public Object convert(Object value, String key)

      Converts a given value.

      Parameters:
        `value` - the object to convert
        `key` - the key name for the value, may be `null`
      Returns:
        the converted object

    - #### @Override
      public boolean equals(Object o)

      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.

      Parameters:
        `o` - the object with which to compare.
      Returns:
        `true` if this object contains the same class; `false` otherwise.

    - #### @Override
      public boolean handles(Class<?> type)

      Returns `true` if this converter can handle conversions of the given type.

      Parameters:
        `type` - the type of the object to convert
      Returns:
        true if this converter can successfully convert values of the given type

    - #### @Override
      public int hashCode()

    - #### @Override
      public String toString()