@@ -46,29 +46,47 @@ public EntryModel(JSONObject response) {
46
46
}
47
47
48
48
if (this .jsonObject .has (UID_KEY )) {
49
- this .uid = ( String ) this .jsonObject .opt (UID_KEY );
49
+ this .uid = this .jsonObject .optString (UID_KEY , null );
50
50
}
51
51
if (this .jsonObject .has (TITLE_KEY )) {
52
- this .title = ( String ) this .jsonObject .opt (TITLE_KEY );
52
+ this .title = this .jsonObject .optString (TITLE_KEY , null );
53
53
}
54
54
if (this .jsonObject .has (LOCALE_KEY )) {
55
- this .language = ( String ) this .jsonObject .opt (LOCALE_KEY );
55
+ this .language = this .jsonObject .optString (LOCALE_KEY , null );
56
56
}
57
57
if (this .jsonObject .has (URL_KEY )) {
58
- this .url = ( String ) this .jsonObject .opt (URL_KEY );
58
+ this .url = this .jsonObject .optString (URL_KEY , null );
59
59
}
60
60
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
+ }
72
90
if (this .jsonObject .has (PUBLISH_DETAIL_KEY )) {
73
91
parsePublishDetail ();
74
92
}
@@ -77,12 +95,15 @@ public EntryModel(JSONObject response) {
77
95
78
96
private void parsePublishDetail () {
79
97
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
+ }
84
104
}
85
105
this .metadata = new HashMap <>();
86
106
this .metadata .put (PUBLISH_DETAIL_KEY , this .publishDetails );
87
107
}
88
108
}
109
+
0 commit comments