#jackson json question
21 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @mild galleon! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
You can not update contents of a file without rewriting the contents of a file.
Vice versa, if you do not change the file you do not update the file.
well then, what would be the recommended way to do that with jackson? how can i just update it
Is it a static file?
static file?
I mean: Are you sure the file exists?
yes
Try
ObjectMapper om = new ObjectMapper();
var root = om.readValue(projects.toFile(), JsonNode.class);
//change the contents of the root according to your update
FileWriter fw = new FileWriter(projects.toFile());
fw.write(om.writeValueAsString(root));
fw.close();```
@civic briar thanks it works, any idea if Path can be converted from string with jackson?
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Hm, is this a different question?
well its unrelated to my first question
do i need to make new thread
I mean, Jackson could serialize Path just fine. I did it just now.
where the hell is the problem then
No idea, this code works for me:
ObjectMapper om = new ObjectMapper();
var a = om.readValue("{\"p\":\"file:///C:/Users/basdfa/Downloads\"}", A.class);
System.out.println(a.p);