public static Word convertJSONObjectToWordWithMeanings(JSONObject wordJsonObject) throws JSONException, ParseException { Word word = null; JSONArray arrayMeaningJSON = null; List<Meaning> meanings = null; if (wordJsonObject != null) { Log.v(TAG, "wordJsonObject->" + wordJsonObject.toString()); String idWord = wordJsonObject.getString("id"); String creationDateStr = wordJsonObject.getString("creationDate"); String creationTimeStr = wordJsonObject.getString("creationTime"); String modificationDateStr = wordJsonObject.getString("modificationDate"); String modificationTimeStr = wordJsonObject.getString("modificationTime"); String statusWord = wordJsonObject.getString("status"); String textWord = wordJsonObject.getString("text"); Date creationDateWord = GeneralUtils.convertStringToDateSQL(creationDateStr, ConstantsFormat.FORMAT_DATE_1); Time creationTimeWord = GeneralUtils.convertStringToTimeSQL(creationTimeStr); Date modificationDateWord = GeneralUtils.convertStringToDateSQL(modificationDateStr, ConstantsFormat.FORMAT_DATE_1); Time modificationTimeWord = GeneralUtils.convertStringToTimeSQL(modificationTimeStr); // Meanings String meaningsWordStr = wordJsonObject.getString("meanings"); if (meaningsWordStr.equals("null")) { meanings = new ArrayList<Meaning>(); } else if (meaningsWordStr.isEmpty()) { meanings = new ArrayList<Meaning>(); } else if (meaningsWordStr == null) { meanings = new ArrayList<Meaning>(); } else if (meaningsWordStr.equals("[]")) { meanings = new ArrayList<Meaning>(); } else { arrayMeaningJSON = new JSONArray(meaningsWordStr); meanings = ConvertsTypeMeaning.convertJSONArrayToArrayListMeanings(arrayMeaningJSON); } word = new Word(); word.setId(idWord); word.setCreationDate(creationDateWord); word.setCreationTime(creationTimeWord); word.setModificationDate(modificationDateWord); word.setModificationTime(modificationTimeWord); word.setStatus(statusWord); word.setText(textWord); word.setMeanings(meanings); } else { Log.e(TAG, "JSONObject is null"); } return word; }
public static Word convertJSONObjectToWordWithOutMeanings(JSONObject wordJsonObject) throws JSONException, ParseException { Word word = null; if (wordJsonObject != null) { String idWord = wordJsonObject.getString("id"); String creationDateStr = wordJsonObject.getString("creationDate"); String creationTimeStr = wordJsonObject.getString("creationTime"); String modificationDateStr = wordJsonObject.getString("modificationDate"); String modificationTimeStr = wordJsonObject.getString("modificationTime"); String statusWord = wordJsonObject.getString("status"); String textWord = wordJsonObject.getString("text"); Date creationDateWord = GeneralUtils.convertStringToDateSQL(creationDateStr, ConstantsFormat.FORMAT_DATE_1); Time creationTimeWord = GeneralUtils.convertStringToTimeSQL(creationTimeStr); Date modificationDateWord = GeneralUtils.convertStringToDateSQL(modificationDateStr, ConstantsFormat.FORMAT_DATE_1); Time modificationTimeWord = GeneralUtils.convertStringToTimeSQL(modificationTimeStr); word = new Word(); word.setId(idWord); word.setCreationDate(creationDateWord); word.setCreationTime(creationTimeWord); word.setModificationDate(modificationDateWord); word.setModificationTime(modificationTimeWord); word.setStatus(statusWord); word.setText(textWord); } else { Log.e(TAG, "JSONObject is null"); } return word; }
public static JSONObject convertMeaningWithWordToJSONObject(Meaning meaning) throws JSONException, ParseException { JSONObject meaningToJSONObject = null; JSONObject jsonObjectWord = null; String jsonStr = null; String id = null; Date creationDate = null; Time creationTime = null; Date modificationDate = null; Time modificationTime = null; String status = null; String text = null; String creationDateStr = null; String creationTimeStr = null; String modificationDateStr = null; String modificationTimeStr = null; Word word = null; String idWord = null; String wordStr = null; if (meaning != null) { id = meaning.getId(); creationDate = meaning.getCreationDate(); creationTime = meaning.getCreationTime(); modificationDate = meaning.getModificationDate(); modificationTime = meaning.getModificationTime(); status = meaning.getStatus(); text = meaning.getText(); word = meaning.getWord(); // Converts creationDateStr = GeneralUtils.convertDateSQLToString(creationDate, ConstantsFormat.FORMAT_DATE_1); creationTimeStr = GeneralUtils.convertTimeSQLToString(creationTime, ConstantsFormat.FORMAT_TIME_1); modificationDateStr = GeneralUtils.convertDateSQLToString(modificationDate, ConstantsFormat.FORMAT_DATE_1); modificationTimeStr = GeneralUtils.convertTimeSQLToString(creationTime, ConstantsFormat.FORMAT_TIME_1); } else { Log.e(TAG, "Meaning is null"); } if (word != null) { idWord = word.getId(); jsonObjectWord = ConvertsTypeWord.convertWordWithOutMeaningsToJSONObject(word); } else { Log.e(TAG, "Word is null"); } meaningToJSONObject = new JSONObject(); meaningToJSONObject.put("id", id); meaningToJSONObject.put("creationDate", creationDateStr); meaningToJSONObject.put("creationTime", creationTimeStr); meaningToJSONObject.put("modificationDate", modificationDateStr); meaningToJSONObject.put("modificationTime", modificationTimeStr); meaningToJSONObject.put("status", status); meaningToJSONObject.put("text", text); meaningToJSONObject.put("word", jsonObjectWord); return meaningToJSONObject; }