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 Details

  • 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 IOPathResources 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
      Returns:
      a newly created Bundle
    • toBundleList

      public static <T extends IOPath> List<Bundle> toBundleList(String jsonString, Function<String,T> ioPathConstructor)
      Create a List 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
    • toBundleList

      public static List<Bundle> toBundleList(String jsonString)
      Create a List 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