-
-
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
Add a mechanism for writing sequences of values via ObjectWriter.writeValues()
#655
Comments
Thanks for adding this – I'll be using it as soon as it's released :) |
Hey, is it possible to choose separator? It uses I tried @cowtowncoder It is weird though because based on the documentation :
It should be it, right? I'm using :
Code : object ObjMapper extends ObjectMapper with ScalaObjectMapper {
setSerializationInclusion(JsonInclude.Include.NON_NULL)
registerModule(DefaultScalaModule)
val prettyWriter = writer(new DefaultPrettyPrinter)
val miniWriter = writer(new MinimalPrettyPrinter)
}
def writeJson(file: File, recs: Seq[Rec]) = {
import scala.collection.JavaConverters._
var writer: SequenceWriter = null
try {
writer =
ObjMapper
.miniWriter
.withRootValueSeparator("\n")
.writeValues(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), StandardCharsets.UTF_8), 32768))
.writeAll(recs.asJava)
} finally Option(writer).foreach(_.close())
} And this is the result if you write sequence twice into a file: {"1":1} {"2":2} {"3":3}{"1":1} {"2":2} {"3":3} |
Got it, it was the |
It has been possible to read value sequences with
ObjectReader.readValues()
for a while; this is especially useful for formats likeCSV
that are basically sequences of more or less uniform values.But there is no similar mechanism for writing, so developers have to construct
JsonGenerator
directly first, then useObjectMapper
(orObjectWriter
) on that. This is cumbersome.It would make sense to add a new sequence writer abstraction, accessible via
ObjectWriter
; method could be namedObjectWriter.writeValues()
.The text was updated successfully, but these errors were encountered: