Hi,
Is it possible to access the `objectMapper` from a custom `JsonSerializer`?
Imagine a serializer like:
class JsonapiDocumentSerializer : StdSerializer<JsonapiDocument>(
JsonapiDocument::class.java) {
@Throws(IOException::class)
override fun serialize(jsonapiDocument: JsonapiDocument, json:
JsonGenerator, provider: SerializerProvider) {
json.writeStartObject()
// Would like to do something like:
val dataJson: ObjectNode = objectMapper.valueToTree(
jsonapiDocument.data)
// And then manipulate the dataJson like:
// - removing fields
// - extract particular nodes and add them to an included
`ArrayNode`
val includedJson = ArrayNode // create `ArrayNode` (how to
create it from JsonSerializer?) and add data from dataJson
json.writeObjectField("data", dataJson)
json.writeObjectField("included", includedJson)
// Do other stuff:
jsonapiDocument.meta?.let { json.writeObjectField("meta", it) }
jsonapiDocument.jsonapi?.let { json.writeObjectField("jsonapi",
it) }
jsonapiDocument.links?.let { json.writeObjectField("links", it)
}
json.writeEndObject()
}
}
I would like to call the objectMapper valueToTree, manipulate the data and
the write it in the object.
Br,
Marcel
--
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.