-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
#2013: add support for reading from / writing to a Path #3066
Conversation
I mentioned non-default file systems as a use case that is not supported by the I think your implementation supports this use case, but do you think it's worth adding a test to verify this? Here's a sketch of such a test. This might work as written, but I didn't try it in the context of this PR. /**
* Verifies that {@link ObjectMapper} can read from and write to {@link Path}s
* whose {@link Path#getFileSystem()} is not the {@linkplain
* FileSystems#getDefault() default file system}.
*/
public void testNonDefaultFileSystem() throws IOException {
Map<String, Integer> value = Collections.singletonMap("a", 1);
ObjectMapper mapper = new ObjectMapper();
Path zipFile = Files.createTempFile("ObjectMapperTest", ".zip");
try {
// Write an empty zip archive to the temp file.
try (OutputStream out = Files.newOutputStream(zipFile);
ZipOutputStream zipped = new ZipOutputStream(out)) {
}
// Open the empty zip archive as a file system.
try (FileSystem zipFs = FileSystems.newFileSystem(zipFile, (ClassLoader) null)) {
Path jsonFile = zipFs.getPath("/test.json");
mapper.writeValue(jsonFile, value);
String serialized = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
assertEquals("{\"a\":1}", serialized);
Map<String, Integer> deserialized =
mapper.readValue(jsonFile, new TypeReference<Map<String, Integer>>() {});
assertEquals(value, deserialized);
}
} finally {
Files.delete(zipFile);
}
} |
Yeah, sure. I'm always pro tests. Perhaps the maintainer can clarify. |
Ok, just to make sure: lack of testing for File-sourced/targeted methods is likely just laziness on my part, not having originally added verification -- tests are mostly added for reported bugs/regression, and new features. There have been occasional efforts to extend test coverage, but that often focuses on pieces that seem more likely to break, and to be honest But I think that going forward it is valuable to add tests for new code, even if there are gaps with existing methods. And I'd be +1 for adding tests for gaps too, of course, but that's more optional. So I would like to see @michaelhixson's contribution added. And we can start with 3.0, then think whether 2.13 would make sense or not; I have no strong opinion there. With that, just one more thing @sdoeringNew : unless I have asked for and received CLA (from https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf), that'd be needed. Looking forward to getting this merged! |
bef42f6
to
6a69eb5
Compare
Besides @michaelhixson test case I've added some more Unit tests. The contribution has been signed and send. |
try { | ||
runnable.run(); | ||
fail("IllegalArgumentException expected."); | ||
} catch (IllegalArgumentException expected) { |
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.
Typically should verify exception message; I can add that.
Thank you @sdoeringNew -- as with jackson-core, addition of test much appreciated! |
* @since 3.0 | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public <T> T readValue(Path p) throws JacksonException |
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.
Will change p
to path
just because p
traditionally refers to JsonParser
(or whatever it'll get renamed as)
Here, too, there seems no need for adding unit tests. 😨
That PR is the counterpart to: FasterXML/jackson-core#680