The Javadoc on IonSystem indicates to use IonSystem.clone to create a copy of value for use by a different system.
|
* In general, {@link IonValue} instances returned from one system instance |
|
* are not interoperable with those returned by other instances. |
|
* The intended usage pattern is for an application to construct a single |
|
* <code>IonSystem</code> instance and use it throughout, |
|
* rather than constructing multiple systems and intermingling their use. |
|
* To create a copy of a value for use by a different system, use |
|
* {@link #clone(IonValue)}. |
|
* <p> |
|
* To create an {@code IonSystem}, |
|
* see {@link com.amazon.ion.system.IonSystemBuilder}. |
|
* <p> |
Similarly, the Javadoc on ValueFactory which IonSystems extends mentions that clone does the deep copy and it allows you to shift data from one factory instance to another.
|
/** |
|
* Creates a deep copy of an Ion value. This method can properly clone |
|
* {@link IonDatagram}s. |
|
* <p> |
|
* The given value can be in the context of any {@code ValueFactory}, |
|
* and the result will be in the context of this one. This allows you to |
|
* shift data from one factory instance to another. |
|
* |
|
* @param value the value to copy. |
|
* |
|
* @return a deep copy of value, with no container. |
|
* |
|
* @throws NullPointerException if {@code value} is null. |
|
* @throws IonException if there's a problem creating the clone. |
|
* @throws UnknownSymbolException |
|
* if any part of this value has unknown text but known Sid for |
|
* its field name, annotation or symbol. |
|
* |
|
* @see IonValue#clone() |
|
*/ |
So, I'd expect that when I do ionSystem.clone(ionValue) then result is a deep copy with everything with ionSystem, but I found this test fails indicating it didn't do that.
@Test
public void testIonSystem() {
IonSystem ionSystem1 = IonSystemBuilder.standard().build();
IonSystem ionSystem2 = IonSystemBuilder.standard().build();
IonSystem ionSystem3 = IonSystemBuilder.standard().build();
IonStruct requestStruct = (IonStruct) ionSystem1.singleValue("{" +
"request_id:1234," +
"item_id:\"item_1\"" +
"}");
IonStruct responseStruct = (IonStruct) ionSystem2.singleValue("{" +
"status:success," +
"request_id:1234," +
"item_id:\"item_1\"" +
"}");
IonStruct container = ionSystem3.newEmptyStruct();
container.add("request", requestStruct);
container.add("response", responseStruct);
IonStruct finalStruct = ionSystem3.clone(container);
assertEquals(finalStruct.get("request").getSystem(), finalStruct.get("response").getSystem()) ;
}
The Javadoc on IonSystem indicates to use IonSystem.clone to create a copy of value for use by a different system.
ion-java/src/main/java/com/amazon/ion/IonSystem.java
Lines 33 to 43 in 9e6c570
Similarly, the Javadoc on ValueFactory which IonSystems extends mentions that clone does the deep copy and it allows you to shift data from one factory instance to another.
ion-java/src/main/java/com/amazon/ion/ValueFactory.java
Lines 570 to 589 in 9e6c570
So, I'd expect that when I do
ionSystem.clone(ionValue)then result is a deep copy with everything with ionSystem, but I found this test fails indicating it didn't do that.