I have a domain object which is being created fine from a POST method body by jackson.
@Entity("payloads")
@Data
@NoArgsConstructor
class Payload{
@Id
String payloadId;
JsonNode data;
}
But when I try to persist this in mongodb I am getting the following error -
org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.fasterxml.jackson.databind.node.JsonNodeFactory.
I understand that instead of using JsonNode, I could create a class for data and either embed or reference it in payloads collection. But my problem is the structure of data is dynamic and I just want to save the Json data in mongo.
Is there anyway I could achieve this?
Document d = new Document("_id", payloadId).append("data", Document.parse(jsonString)); dbCollection.insertOne(d);{_id:xxx, data:{json}}. This is what you'll get with the example above. Or you mean something flat like{_id:xxx, fields in the json here...}?{_id:xxx, field1: {..}, field2: {..}, data:{json}}new Document("_id", payloadId).append("data", Document.parse(jsonString)).append("field1":X).append("field2":Y);