Class CollectionBuilder

  • Direct Known Subclasses:
    CollectionBuilder.Default

    public abstract class CollectionBuilder
    extends Object
    Helper class that is used for constructing Collections to map JSON Array values in.

    Objects server both as "factories" for creating new builders (blueprint style), and as actual builders. For each distinct read operation, newBuilder(int) will be called at least once; this instance may be used and reused multiple times, as calling start() will reset the state so that more Collections may be built.

    • Field Detail

      • EMPTY_ARRAY

        protected static final Object[] EMPTY_ARRAY
      • _features

        protected final int _features
      • _collectionType

        protected final Class<?> _collectionType
        Optional Collection implementation class, used when specific implementation is desired.
    • Constructor Detail

      • CollectionBuilder

        protected CollectionBuilder​(int features,
                                    Class<?> collImpl)
    • Method Detail

      • isEnabled

        public final boolean isEnabled​(JSON.Feature f)
      • buildCollection

        public abstract Collection<Object> buildCollection()
        The usual build method to use for constructing Collection
      • buildArray

        public Object[] buildArray()
        Alternative build method used when desired result type is Object[]
      • buildArray

        public <T> T[] buildArray​(Class<T> type)
      • emptyCollection

        public Collection<Object> emptyCollection()
        Specialized method that is called when an empty Collection needs to be constructed; this may be a new Collection, or an immutable shared one, depending on implementation.

        Default implementation simply calls:

          start().buildCollection();
        
      • emptyArray

        public Object[] emptyArray()
        Specialized method that is called when an empty Object[] needs to be returned.

        Default implementation simply returns a shared empty array instance.

      • emptyArray

        public <T> T[] emptyArray​(Class<T> type)
      • singletonCollection

        public Collection<Object> singletonCollection​(Object value)
        Specialized method that is called when a single-entry Collection needs to be constructed.

        Default implementation simply calls:

          start().add(value).buildCollection();
        
      • singletonArray

        public Object[] singletonArray​(Object value)
        Specialized method that is called when a single-entry array needs to be constructed.

        Default implementation simply returns equivalent of:

           new Object[] { value }
        
      • singletonArray

        public <T> T[] singletonArray​(Class<?> type,
                                      T value)