Skip to content

Commit

Permalink
Restores previous behavior when IonValue.writeTo is called with a wri…
Browse files Browse the repository at this point in the history
…ter that has annotations set.
  • Loading branch information
tgregg committed Sep 15, 2023
1 parent 422360c commit 5ac5283
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/com/amazon/ion/impl/lite/IonValueLite.java
Original file line number Diff line number Diff line change
Expand Up @@ -1168,9 +1168,7 @@ private static void writeFieldNameAndAnnotations(IonWriter writer, IonValueLite
}
}

if (value._annotations != null) {
writer.setTypeAnnotationSymbols(value._annotations);
}
writer.setTypeAnnotationSymbols(value._annotations);
}

/* The following template may be used to iterate over the tree at the current value. Copying this structure
Expand Down
20 changes: 20 additions & 0 deletions test/com/amazon/ion/impl/IonWriterTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static com.amazon.ion.impl.Symtabs.FRED_MAX_IDS;
import static com.amazon.ion.impl._Private_IonWriterBase.ERROR_MISSING_FIELD_NAME;
import static com.amazon.ion.impl._Private_Utils.newSymbolToken;
import static com.amazon.ion.junit.IonAssert.assertAnnotations;
import static com.amazon.ion.junit.IonAssert.assertIonEquals;
import static com.amazon.ion.junit.IonAssert.expectNextField;

Expand Down Expand Up @@ -1288,4 +1289,23 @@ public void testWriteToWithFieldName()

assertNull(reader.next());
}

// Create a writer, set it using the provided annotations, then write the given value using IonValue.writeTo.
// Assert that the resulting value is annotated with only the annotations on the original IonValue, not the ones
// set on the writer.
private void writeToWithAnnotations(IonValue value, String... annotations) throws Exception {
iw = makeWriter();
iw.setTypeAnnotations(annotations);
value.writeTo(iw);
IonValue reread = system().singleValue(outputByteArray());
assertAnnotations(reread, value.getTypeAnnotations());
}

@Test
public void writeToOverwritesExistingAnnotations() throws Exception {
writeToWithAnnotations(system().singleValue("bar"));
writeToWithAnnotations(system().singleValue("foo::bar"));
writeToWithAnnotations(system().singleValue("foo"), "bar");
writeToWithAnnotations(system().singleValue("foo::bar"), "baz");
}
}

0 comments on commit 5ac5283

Please sign in to comment.