Package org.apache.tapestry5.json

# Class JSONCollectors

java.lang.Object
org.apache.tapestry5.json.JSONCollectors

public final class JSONCollectors extends Object
Implementations of `Collector` that implement reductions to `JSONArray` and to `JSONObject`.

Since:
  5.7

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> Collector<T,?,JSONArray>`
  `toArray()`
  Returns a `Collector` that accumulates the input elements into a new `JSONArray`.
  `static <T> Collector<T,?,JSONObject>`
  `toMap(Function<? super T,String> keyMapper, Function<? super T,Object> valueMapper)`
  Returns a `Collector` that accumulates elements into a `JSONObject` whose keys and values are the result of applying the provided mapping functions to the input elements.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### toArray

    public static <T> Collector<T,?,JSONArray> toArray()
    Returns a `Collector` that accumulates the input elements into a new `JSONArray`.
    Type Parameters:
      `T` - the type of the input elements
    Returns:
      a `Collector` which collects all the input elements into a `JSONArray`, in encounter order
    Since:
      5.7

  - ### toMap

    public static <T> Collector<T,?,JSONObject> toMap(Function<? super T,String> keyMapper, Function<? super T,Object> valueMapper)
    Returns a `Collector` that accumulates elements into a `JSONObject` whose keys and values are the result of applying the provided mapping functions to the input elements. In case of duplicate keys an `IllegalStateException` is thrown when the collection operation is performed.
    Type Parameters:
      `T` - the type of the input elements
    Parameters:
      `keyMapper` - a mapping function to produce String keys
      `valueMapper` - a mapping function to produce values
    Returns:
      a `Collector` which collects elements into a `JSONObject` whose keys and values are the result of applying mapping functions to the input elements
    Since:
      5.7