This document describes all APIs intended for public consumption, limited to the packages listed here. The ion-java library distribution includes other packages not documented here; use of those packages is not supported.
More generally: Any behavior or features not present in this API documentation is unsupported, probably untested, and subject to change without notice.
In addition, unless otherwise noted, interfaces and classes listed here should not be implemented or extended by code outside of this library. We may add or remove API(s) of existing interfaces or classes in future releases.
What all this means is that your first task is acquiring a system instance, and for that we turn to {@link software.amazon.ion.system.IonSystemBuilder IonSystemBuilder}. Here's the easiest way to bootstrap:
IonSystem ion = IonSystemBuilder.standard().build();
That should be sufficient for many, but not all, applications. Long-running
services will probably want to use a non-default
{@linkplain software.amazon.ion.IonCatalog catalog} by configuring the builder
before calling {@link software.amazon.ion.system.IonSystemBuilder#build() build()}.
IonSystem sys1 = IonSystemBuilder.standard().build();
IonSystem sys2 = IonSystemBuilder.standard().build();
IonList parent = sys1.newEmptyList();
IonInt child = sys2.newInt(23);
parent.add(child); // NOT SUPPORTED
Given any {@code IonValue} instance it is possible to retrieve the relevant
system via {@link software.amazon.ion.IonValue#getSystem()}.
This is generally the best way to ensure
that you're using the correct system while modifying existing trees.
You can also use the "Curried" insertion methods to add new values to
collections:
struct.put("f").newInt(3);
list.add().newString("demo");
To construct an {@code IonReader}, call one of the {@code newReader} methods on {@code IonSystem}; for example {@link software.amazon.ion.IonSystem#newReader(InputStream)}. You can then pull data from the reader. Don't forget to {@link software.amazon.ion.IonReader#close() close} it when you're done!
Ion iterators are extensions of {@link java.util.Iterator} so they are used once and then discarded. Use the various {@code iterate} methods on {@code IonSystem} to create them; for example {@link software.amazon.ion.IonSystem#iterate(InputStream)}.
To construct an {@code IonLoader}, call {@link software.amazon.ion.IonSystem#newLoader()} and configure it as necessary. {@code IonLoaders} are safe for use by multiple threads. The {@code IonSystem} also maintains a "default loader" so you don't have to pass one around, see {@link software.amazon.ion.IonSystem#getLoader()}.
Therefore, applications and tests should never compare the serialized form of data to determine equality. For example, the following JUnit idiom is not supported:
assertEquals(expectedIonValue.toString(), actualIonValue.toString());
The same goes for output via any other API, including
{@link software.amazon.ion.IonWriter IonWriter}s.
The correct approach to performing semantic equivalence checks over Ion data is to use documented equivalence APIs such as {@link software.amazon.ion.IonValue#equals(Object) IonValue.equals()}.
To output JSON with this library, Ion data can be "downconverted" to JSON format using an {@link software.amazon.ion.system.IonTextWriterBuilder IonTextWriterBuilder}. This replaces Ion-only datatypes with more-or-less equivalent JSON values.