We need to create DocumentV2 instances based on data retrieved from a database table.
The DocumentV2 API offers a convenient way to create an instance. However, it seems I can only pass Strings to to putFieldValue() or FieldInstanceV2.ofValue()
So the following will fail with an IllegalArgumentException
List<UpdateAction> updates = List.of(
UpdateAction.putFieldValue("/Root/Name", "Arthur"),
UpdateAction.putFieldValue("/Root/Amount", 42)
);
Based on some threads here in the forum, it seems I have to use an instance of IDmAwareDocService to create values other than strings - however the input is always as string. So I retrieve an Integer from the database, then I need to convert it to a String, which is then converted back to a FieldInstanceV2.
This seems quite an overhead given that IDocumentV2Serializer will happily serialize a JSON string that contains an integer.
To make my live easier, I am considering creating a valid JSON string, then use IDocumentV2Serializer to create a DocumentV2. But that means I first create a JsonNode object (using Jackson) serialize that to a String then convert that to a DocumentV2 which seems a lot of intermediate steps.
My question basically boils down to: is there an easier (=more efficient) way to directly create a Document where I know that the values are all correct (=instances of the correct class)?