@@ -46,29 +46,47 @@ public EntryModel(JSONObject response) {
4646 }
4747
4848 if (this .jsonObject .has (UID_KEY )) {
49- this .uid = ( String ) this .jsonObject .opt (UID_KEY );
49+ this .uid = this .jsonObject .optString (UID_KEY , null );
5050 }
5151 if (this .jsonObject .has (TITLE_KEY )) {
52- this .title = ( String ) this .jsonObject .opt (TITLE_KEY );
52+ this .title = this .jsonObject .optString (TITLE_KEY , null );
5353 }
5454 if (this .jsonObject .has (LOCALE_KEY )) {
55- this .language = ( String ) this .jsonObject .opt (LOCALE_KEY );
55+ this .language = this .jsonObject .optString (LOCALE_KEY , null );
5656 }
5757 if (this .jsonObject .has (URL_KEY )) {
58- this .url = ( String ) this .jsonObject .opt (URL_KEY );
58+ this .url = this .jsonObject .optString (URL_KEY , null );
5959 }
6060 if (this .jsonObject .has ("description" )) {
61- this .description = this .jsonObject .opt ("description" );
62- }
63- this .images = (JSONArray ) this .jsonObject .opt ("images" );
64- this .isDirectory = (Boolean ) this .jsonObject .opt ("is_dir" );
65- this .updatedAt = (String ) this .jsonObject .opt ("updated_at" );
66- this .updatedBy = (String ) this .jsonObject .opt ("updated_by" );
67- this .createdAt = (String ) this .jsonObject .opt ("created_at" );
68- this .createdBy = (String ) this .jsonObject .opt ("created_by" );
69- this .locale = (String ) this .jsonObject .opt (LOCALE_KEY );
70- this .inProgress = (Boolean ) this .jsonObject .opt ("_in_progress" );
71- this .version = this .jsonObject .opt ("_version" ) != null ? (int ) this .jsonObject .opt ("_version" ) : 1 ;
61+ this .description = this .jsonObject .optString ("description" );
62+ }
63+ if (this .jsonObject .has ("images" ) && this .jsonObject .opt ("images" ) instanceof JSONArray ) {
64+ this .images = this .jsonObject .optJSONArray ("images" );
65+ }
66+ if (this .jsonObject .has ("is_dir" ) && this .jsonObject .opt ("is_dir" ) instanceof Boolean ) {
67+ this .isDirectory = this .jsonObject .optBoolean ("is_dir" );
68+ }
69+ if (this .jsonObject .has ("updated_at" )) {
70+ this .updatedAt = this .jsonObject .optString ("updated_at" );
71+ }
72+ if (this .jsonObject .has ("updated_by" )) {
73+ this .updatedBy = this .jsonObject .optString ("updated_by" );
74+ }
75+ if (this .jsonObject .has ("created_at" )) {
76+ this .createdAt = this .jsonObject .optString ("created_at" );
77+ }
78+ if (this .jsonObject .has ("created_by" )) {
79+ this .createdBy = this .jsonObject .optString ("created_by" );
80+ }
81+ if (this .jsonObject .has (LOCALE_KEY )) {
82+ this .locale = this .jsonObject .optString (LOCALE_KEY );
83+ }
84+ if (this .jsonObject .has ("_in_progress" ) && this .jsonObject .opt ("_in_progress" ) instanceof Boolean ) {
85+ this .inProgress = this .jsonObject .optBoolean ("_in_progress" );
86+ }
87+ if (this .jsonObject .has ("_version" ) && this .jsonObject .opt ("_version" ) instanceof Integer ) {
88+ this .version = this .jsonObject .optInt ("_version" ,1 );
89+ }
7290 if (this .jsonObject .has (PUBLISH_DETAIL_KEY )) {
7391 parsePublishDetail ();
7492 }
@@ -77,12 +95,15 @@ public EntryModel(JSONObject response) {
7795
7896 private void parsePublishDetail () {
7997 if (this .jsonObject .opt (PUBLISH_DETAIL_KEY ) instanceof JSONObject ) {
80- this .publishDetails = (JSONObject ) this .jsonObject .opt (PUBLISH_DETAIL_KEY );
81- this .environment = this .publishDetails .optString ("environment" );
82- this .time = this .publishDetails .optString ("time" );
83- this .user = this .publishDetails .optString ("user" );
98+ this .publishDetails = this .jsonObject .optJSONObject (PUBLISH_DETAIL_KEY );
99+ if (this .publishDetails != null ) {
100+ this .environment = this .publishDetails .optString ("environment" );
101+ this .time = this .publishDetails .optString ("time" );
102+ this .user = this .publishDetails .optString ("user" );
103+ }
84104 }
85105 this .metadata = new HashMap <>();
86106 this .metadata .put (PUBLISH_DETAIL_KEY , this .publishDetails );
87107 }
88108}
109+
0 commit comments