# Class BundleJSON

java.lang.Object
htsjdk.beta.io.bundle.BundleJSON

public class BundleJSON extends Object
Methods for serializing and deserializing Bundles to and from JSON strings.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`BUNDLE_EXTENSION`
`static final String`
`JSON_PROPERTY_FORMAT`
`static final String`
`JSON_PROPERTY_PATH`
`static final String`
`JSON_PROPERTY_PRIMARY`
`static final String`
`JSON_PROPERTY_SCHEMA`
`static final String`
`JSON_PROPERTY_SCHEMA_NAME`
`static final String`
`JSON_PROPERTY_SCHEMA_VERSION`
`static final String`
`JSON_SCHEMA_NAME`
`static final String`
`JSON_SCHEMA_VERSION`

## Constructor Summary

Constructors
Constructor
Description
`BundleJSON()`

## Method Summary

Modifier and Type
Method
Description
`static Bundle`
`toBundle(String jsonString)`
Create a Bundle from a jsonString.
`static <T extends IOPath>
Bundle`
`toBundle(String jsonString, Function<String,T> ioPathConstructor)`
Create a Bundle from jsonString using a custom class that implements `IOPath` for all resources.
`static List<Bundle>`
`toBundleList(String jsonString)`
Create a List<Bundle> from a jsonString.
`static <T extends IOPath>
List<Bundle>`
`toBundleList(String jsonString, Function<String,T> ioPathConstructor)`
Create a List<Bundle> from a jsonString, using a custom class that implements `IOPath` for all resources.
`static String`
`toJSON(Bundle bundle)`
Serialize a bundle to a JSON string representation.
`static String`
`toJSON(List<Bundle> bundles)`
Convert a (non-empty) List of Bundles to a JSON array string representation.

### Methods inherited from class Object

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

## Field Details

### BUNDLE_EXTENSION

public static final String BUNDLE_EXTENSION

See Also:
  - Constant Field Values

### JSON_PROPERTY_SCHEMA

public static final String JSON_PROPERTY_SCHEMA

See Also:
  - Constant Field Values

### JSON_PROPERTY_SCHEMA_NAME

public static final String JSON_PROPERTY_SCHEMA_NAME

See Also:
  - Constant Field Values

### JSON_PROPERTY_SCHEMA_VERSION

public static final String JSON_PROPERTY_SCHEMA_VERSION

See Also:
  - Constant Field Values

### JSON_PROPERTY_PRIMARY

public static final String JSON_PROPERTY_PRIMARY

See Also:
  - Constant Field Values

### JSON_PROPERTY_PATH

public static final String JSON_PROPERTY_PATH

See Also:
  - Constant Field Values

### JSON_PROPERTY_FORMAT

public static final String JSON_PROPERTY_FORMAT

See Also:
  - Constant Field Values

### JSON_SCHEMA_NAME

public static final String JSON_SCHEMA_NAME

See Also:
  - Constant Field Values

### JSON_SCHEMA_VERSION

public static final String JSON_SCHEMA_VERSION

See Also:
  - Constant Field Values

## Constructor Details

### BundleJSON

public BundleJSON()

## Method Details

### toJSON

public static String toJSON(Bundle bundle)
Serialize a bundle to a JSON string representation. All resources in the bundle must be `IOPathResource`s for serialization to succeed. Stream resources cannot be serialized.

Parameters:
  `bundle` - the `Bundle` to serialize to JSON
Returns:
  a JSON string representation of this bundle
Throws:
  `IllegalArgumentException` - if any resource in bundle is not an IOPathResources.

### toJSON

public static String toJSON(List<Bundle> bundles)
Convert a (non-empty) List of Bundles to a JSON array string representation.

Parameters:
  `bundles` - a List of Bundles to serialize to JSON
Returns:
  a JSON string (array) representation of the list of bundles

### toBundle

public static Bundle toBundle(String jsonString)
Create a Bundle from a jsonString.

Parameters:
  `jsonString` - a valid JSON string conforming to the bundle schema (for compatibility, a bundle list is also accepted, as long as it only contains a single bundle)
Returns:
  a `Bundle` created from jsonString

### toBundle

public static <T extends IOPath> Bundle toBundle(String jsonString, Function<String,T> ioPathConstructor)
Create a Bundle from jsonString using a custom class that implements `IOPath` for all resources. (For compatibility, a bundle list string is also accepted, as long as it only contains a single bundle).

Type Parameters:
  `T` - the IOPath-derived type to use for IOPathResources
Parameters:
  `jsonString` - a valid JSON string conforming to the bundle schema
  `ioPathConstructor` - a function that takes a string and returns an IOPath-derived class of type <T>
Returns:
  a newly created `Bundle`

### toBundleList

public static <T extends IOPath> List<Bundle> toBundleList(String jsonString, Function<String,T> ioPathConstructor)
Create a List<Bundle> from a jsonString, using a custom class that implements `IOPath` for all resources.

Type Parameters:
  `T` - IOPath-derived class to use for IOPathResources
Parameters:
  `jsonString` - the json string must conform to the bundle schema, and may contain an array or single object
  `ioPathConstructor` - constructor to use to create the backing IOPath for all resources
Returns:
  List<Bundle>

### toBundleList

public static List<Bundle> toBundleList(String jsonString)
Create a List<Bundle> from a jsonString.

Parameters:
  `jsonString` - a JSON strings that conform to the bundle schema; may be an array or single object
Returns:
  a `List<Bundle>` created from a Collection of jsonStrings