I have a document that consists of some metadata of known structure (time created, name, ID etc) plus some property that contains JSON data of unknown structure. I’ve modeled this in my Spring document using the JsonNode
type for the latter property, but the data written to Couchbase appears to be a JSON representation of the Java JsonNode
object (e.g. it has _class
, _nodeFactory
properties etc) as opposed to the JSON object that the node represents. Is there a way to have the JsonNode
property be serialized as JSON when it’s written to the database?
@mreiche can you please assist ?
I believe a JsonObject would be serialized/deserialized as expected, but I haven’t tried it. If that doesn’t work, you could add a custom converter.
The next thing that comes to mind is putting the toString() of your JsonNode into a string, and doing the reverse on reads.
- Mike
Thanks for assisting. I also have the same problems with my project.
Typing the attribute as Object
and converting back and forth using com.fasterxml.jackson.databind.ObjectMapper
works OK and the data is stored as JSON (as opposed to a string) in the database.
Spoke too soon–I’m now seeing this issue.