-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated to liboscal-java 1.0.2 and addressed changes #91
Conversation
@@ -223,7 +222,14 @@ public Iterable<T> findAll() { | |||
} catch (UnsupportedOperationException | AssertionError e) { | |||
logger.debug("Unparsable content found at {}", filePath); | |||
} catch (IOException e) { | |||
throw new DataRetrievalFailureException("Failure in loading Oscal object.", e); | |||
if (e.getMessage() != null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems potentially brittle but we seem to have lost the more specific exception we previously used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you are saying here. There are three major cases where an IOException
can be thrown now.
- There is a problem reading from the underlying stream.
- The content is malformed JSON.
- The content is malformed OSCAL.
In all cases the content cannot be parsed. Previously 1 and 2 caused an IOException
and 3 caused a BindingException
. Given 2 and 3 are syntax errors, I wanted to normalize the exceptions thrown.
FWIW, there is an IJsonProblemHandler
that is used as a callback from the deserializer to address OSCAL syntax issues. I believe I need to expose an option to override this on the deserializer, to allow for detection of unknown and missing content. This might be better than using the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, there is an
IJsonProblemHandler
that is used as a callback from the deserializer to address OSCAL syntax issues. I believe I need to expose an option to override this on the deserializer, to allow for detection of unknown and missing content. This might be better than using the exception.
Yeah, saw that, and yes that could be helpful.
We might also take an approach of some simple content detection first rather than jumping straight into trying to load.
public void serialize(@NotNull T data, @NotNull OutputStream os) throws IOException { | ||
OutputStreamWriter writer = new OutputStreamWriter(os); | ||
serialize(data, writer); | ||
// Stream is already closed after |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-waltermire-nist, this might be of interest. Perhaps the default behavior of Jackson (closing the stream) changed in the update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add a bit more detail, the part of the tests that were failing essentially just creates a ByteArrayOutputStream and ends up calling ISerializer
where writer.flush
fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird that this is happening now. It should have happened all along. Looks like Jackson's default behavior is to auto-close the stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change the default behavior? I believe I should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a simple test in OscalBindingContextTest
in liboscal-java
that fails with the same error:
@Test
void testSerializeSspToOutputStream() throws IOException {
SystemSecurityPlan ssp = new SystemSecurityPlan();
IBindingContext context = IBindingContext.newInstance();
ISerializer<SystemSecurityPlan> serializer = context.newSerializer(Format.JSON, SystemSecurityPlan.class);
serializer.enableFeature(Feature.SERIALIZE_ROOT);
ByteArrayOutputStream out = new ByteArrayOutputStream();
serializer.serialize(ssp, out);
}
That didn't seem worth creating a PR into liboscal-java
and the fix into metaschema-java
, but I can do that if you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the bigger concern is that the out-of-the-box metaschema serializer currently fails, regardless of what the calling code would want to do with that stream after serialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'll look into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I ran your unit test. This is caused by the Jackson autoclose behavior. I am going to disable it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks!
@rgauss It looks like the changes here are minimal based on the liboscal-java API adjustments. Glad to see this. |
...ry-commons/src/main/java/com/easydynamics/oscal/data/marshalling/IterableJsonSerializer.java
Outdated
Show resolved
Hide resolved
...ry-commons/src/main/java/com/easydynamics/oscal/data/marshalling/IterableJsonSerializer.java
Outdated
Show resolved
Hide resolved
67020fc
to
742ef3a
Compare
Yes, that was right. Rebased, should be good to go. |
No description provided.