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; }