Skip to content

Commit

Permalink
Improved exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rgauss committed May 27, 2022
1 parent 09e7041 commit 742ef3a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public IterableJsonSerializer(IBindingContext bindingContext,
super(bindingContext, classBinding);
}

public void serializeIterable(Iterable<T> data, OutputStream out) throws BindingException {
public void serializeIterable(Iterable<T> data, OutputStream out) throws IOException {
serializeIterable(data, new OutputStreamWriter(out));
}

Expand All @@ -36,15 +36,12 @@ public void serializeIterable(Iterable<T> data, OutputStream out) throws Binding
* @param writer the writer to write to
* @throws BindingException thrown when the class binding fails
*/
public void serializeIterable(Iterable<T> data, Writer writer) throws BindingException {
try {
JsonGenerator generator = newJsonGenerator(writer);
public void serializeIterable(Iterable<T> data, Writer writer) throws IOException {
try (JsonGenerator generator = newJsonGenerator(writer)) {
IterableAssemblyClassBinding classBinding = (IterableAssemblyClassBinding) getClassBinding();
IJsonWritingContext writingContext = new DefaultJsonWritingContext(generator);
classBinding.writeRootItems(data, writingContext);
generator.close();
} catch (IOException ex) {
throw new BindingException(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.easydynamics.oscal.data.marshalling.OscalObjectMarshaller;
import com.easydynamics.oscal.data.marshalling.OscalObjectMarshallingException;
import gov.nist.secauto.metaschema.binding.IBindingContext;
import gov.nist.secauto.metaschema.binding.io.BindingException;
import gov.nist.secauto.metaschema.binding.io.Feature;
import gov.nist.secauto.metaschema.binding.io.IDeserializer;
import gov.nist.secauto.metaschema.binding.io.json.DefaultJsonDeserializer;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void toJson(T oscalObject, OutputStream outputStream) {
public void toJson(Iterable<T> oscalObjects, OutputStream outputStream) {
try {
serializer.serializeIterable(oscalObjects, outputStream);
} catch (BindingException e) {
} catch (IOException e) {
throw new OscalObjectMarshallingException(e);
}
}
Expand Down

0 comments on commit 742ef3a

Please sign in to comment.