You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Andrés Ivaldi <ia...@gmail.com> on 2016/11/08 13:06:29 UTC
DataSet toJson
Hello, I'm using spark 2.0 and I'm using toJson method. I've seen that Null
values are omitted in the Json Record, witch is valid, but I need the field
with null as value, it's possible to configure that?
thanks.
Re: DataSet toJson
Posted by Andrés Ivaldi <ia...@gmail.com>.
Ok, digging the code, I find out in the class JacksonGenerator the next
method
private def writeFields(
row: InternalRow, schema: StructType, fieldWriters: Seq[ValueWriter]):
Unit = {
var i = 0
while (i < row.numFields) {
val field = schema(i)
if (!row.isNullAt(i)) {
gen.writeFieldName(field.name)
fieldWriters(i).apply(row, i)
}
i += 1
}
}
So null values are directly ignored, I've to rewrite the method toJson to
use my own JacksonGenerator.
Regards.
On Tue, Nov 8, 2016 at 10:06 AM, Andrés Ivaldi <ia...@gmail.com> wrote:
> Hello, I'm using spark 2.0 and I'm using toJson method. I've seen that
> Null values are omitted in the Json Record, witch is valid, but I need the
> field with null as value, it's possible to configure that?
>
> thanks.
>
>
--
Ing. Ivaldi Andres