Hi,
I am new to v2, and trying to store document using JsonStringDocument and realized that it is stored base64 encoded, and currently view cannot work with that. Should I work with StringDocument or am I missing something?
Oded
Hi,
I am new to v2, and trying to store document using JsonStringDocument and realized that it is stored base64 encoded, and currently view cannot work with that. Should I work with StringDocument or am I missing something?
Oded
Hey Oded,
If what you want to do is store some JSON that you already have obtained as a String (from an external library like Jackson or GSON), then you can use the RawJsonDocument.
JsonStringDocument, JsonArrayDocument, etc⦠where meant for scalar values, ie store a single item rather than a full JSON object, which is not completely equivalent to what you are trying to do (thus the RawJsonDocument was introduced in a following version).
Of course, if youβre not using any third-party JSON libraries, the best supported way is to build JsonObject (using its create methods) rather than plain Strings and work with the JsonDocument.
Happy coding
Simon
But does the document kept in CB as base64 encoded string? Another question: When should I work with JsonDocument and with RawJsonDocument or other?
Both RawJsonDocument and JsonDocument store data in a way views can work with on the server side (that is, a JSON object).
Youβd use mostly JsonDocument if you only deal with domain objects and not JSON in your code:
Domain Object β JsonObject β JsonDocument β Database.
That is, except if you already transform your data into JSON with a String representation (for example by using a JSON library like Jackson or GSON), because in this case using the JsonDocument adds an unnecessary extra step :
not optimized: Object-oriented data β Json String obtained eg via Jackson β extra parsing and conversion to JsonObject β JsonDocument β Database
better: Domain Object β JSON String (using Jackson, β¦) β RawJsonDocument β Database
I hope this is clearer