I have a very large JSON String that i need to store in the data, by very large means more than 48000 characters, and i am using SQL server to store this data in field of text
type, then i tried changing it to nvarchar(max)
but still seems no difference.
The problem that is occurring my string gets truncated after 40000 characters when i insert in the DB. i am using hibernate to store the data in that particular column and mapping it as java.lang.String
following is my code that converts from object to jsonobject
public static JSONObject toJSONListWithKey(List<?> object, String key) {
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
Gson gson = new Gson();
try {
for (Object object2 : object) {
jsonArray.put(new JSONObject(gson.toJson(object2)));
}
if (null != key || !"".equals(key)) {
jsonObject.put(key, jsonArray);
} else {
jsonObject = new JSONObject(jsonArray.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
return jsonObject;
}
and the following is the way i store it in the db
JSONObject jsonObject = JSONUtils.toJSONListWithKey(reports,"reports");
ins.setReportJson(jsonObject.toString());
instanceDAO.update(ins);
Can anyone please suggest/guide me where might things be going wrong and what should i adopt if this approach is not correct?