question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow use of `java.nio.file.Path` for `readValue()`, `writeValue()`

See original GitHub issue

Version 2.9.5 There is no out of box method to read from Path and write to Path, it will be usefull to make these methods.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
michaelhixsoncommented, Feb 18, 2021

Ideally the new methods would not use Path#toFile() because that method throws UnsupportedOperationException if the path is not on the default file system. Examples of non-default file systems include zip file systems and in-memory file systems.

I maintain an application that uses Jackson to interact with both of those types of file systems. If you added methods that accept Path objects but invoke toFile() on them, I wouldn’t be able to use any of those methods.

I’d think it would be better if the Path-accepting methods delegate to {Input,Output}Stream-accepting ones. For example:

public void writeValue(Path resultPath, Object value) throws IOException, JsonGenerationException, JsonMappingException {
    try (OutputStream out = Files.newOutputStream(resultPath)) {
        writeValue(out, value);
    }
}
1reaction
sdoeringNewcommented, Feb 22, 2021

I’ve started with 3.0 and added pull requests for jackson-core and jackson-databind.

I’m unsure about adding it to 2.13, though. It would be a half-heartedly support for Path after the JDK has the nio-package (“new” IO) for ten years now. This issue had the 3.0-label three years and it still can be 3.0. 😏

But if you say so I’ll add it “workaround-ish” to 2.13.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does Jackson automatically deserialize java.nio.file.Path?
Now a simple test shows that it works: ObjectMapper mapper = new ObjectMapper(); ExampleClass exampleClass = mapper. readValue(json, ...
Read more >
Jackson JSON Java Parser API Example Tutorial - DigitalOcean
To use Jackson JSON Java API in our project, we can add it to the project ... readValue() and writeValue() methods to transform...
Read more >
Understanding insecure implementation of Jackson ...
Now, the ObjectMapper class uses the function readValue to read a json data and parse it to java objects. In the above code,...
Read more >
Jackson ObjectMapper - Jenkov.com
The Jackson ObjectMapper can read JSON into Java objects and write ... of readValue() is the source of the JSON (string, stream or...
Read more >
Path (Java Platform SE 8 ) - Oracle Help Center
Returns the name of the file or directory denoted by this path as a Path object. FileSystem · getFileSystem(). Returns the file system...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found