Class CompositeEntry

java.lang.Object
com.blackhillsoftware.json.util.CompositeEntry

public class CompositeEntry extends Object
A class to combine several objects into one logical JSON object. For example, you may want to write JSON containing information from both the SMF 30 Completion Section and SMF 30 Identification Section.

To use, create a new CompositeEntry and add the required objects.

If the object is a complex object with it's own key-value pairs e.g. most SMF sections, use add(Object) to add the JSON key-value pairs from the object to the CompositeEntry.

If the object is a simple object e.g. a string, number, time value etc., or you want the complex object to be nested in the CompositeEntry, use add(String, Object) to specify the the JSON element key name.

  • Constructor Details

    • CompositeEntry

      public CompositeEntry()
      Create a new CompositeEntry
  • Method Details

    • add

      public CompositeEntry add(String key, Object entry)
      Add an object to the composite entry with a specific key
      Parameters:
      key - The JSON key to be used for the object (unique in this entry and not null).
      entry - The object to be added to the combined JSON output.
      Returns:
      this CompositeEntry to allow add methods to be chained.
    • add

      public CompositeEntry add(Object entry)
      Add an object to the composite entry. Simple entries like strings and numbers will receive a generated name - in that case you probably want to use add(String, Object) to specify the name.
      Parameters:
      entry - The object to be added to the combined JSON output.
      Returns:
      this CompositeEntry to allow add methods to be chained.
    • getEntry

      public Object getEntry(String name)
      Get an object from the entry by name (only for entries added with a name)
      Parameters:
      name - the name of the entry
      Returns:
      the object or null
    • getElements

      public List<CompositeEntry.Element> getElements()
      Get the Elements in this CompositeEntry (used when generating JSON)
      Returns:
      a list of Elements
    • toString

      public String toString()
      Overrides:
      toString in class Object