Hi there,
I am using Akka Actor framework to receive messages as Java objects. When I
receive the message, I do the following:
(1) Use ObjectMapper.withPrettyWriter().writeValueAsString(<java pojo>)
(2) Open a file and use java.nio.Files API to write to the file. When I
write to the file, I use Arrays.asList(json_string_from step_1) with file
in *append* mode.
I am having a few issues:
(1) I am unable to write the first json string as an array. When I write it
the first time, I *would like to see*:
[
{
"name" : "test"
"age" : 29
}, --> I don't get this "comma" with closing "]"
] ---> don't get this.
All I get is :
{
"name" : "test"
"age" : 29
}
(2) While calling successive Files.write (...), the output in the file is
{
"name" : "test"
"age" : 29
}
{
"name" : "test2"
"age" : 30
}
This results in malformed JSON file and I cannot use objectMapper.readValue
as a list. Looks like I have to use Files API to load the data.
Qn) How do I write a single json as an array with ", ]" and then append to
this list as data starts flowing in through the messaging architecture?
I did see some solution on reading the file first, add new data to the
array and then write the whole list again to the file each time. I think
with messaging architecture this is not very efficient as we will see a lot
of messages.
Is there someway to open the file and write the first data and then keep
appending to the file?
Thanks
MV
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.