@@ -35,35 +35,35 @@ public ZoneInfo(int ttl, List<String> upDomainsList, Map<String, Long> upDomains
3535 * @throws JSONException
3636 */
3737 public static ZoneInfo buildFromJson (JSONObject obj ) throws JSONException {
38- int ttl = obj . getInt ( "ttl" );
38+
3939 List <String > domainsList = new ArrayList <>();
4040 ConcurrentHashMap <String , Long > domainsMap = new ConcurrentHashMap <>();
41- JSONObject upObj = obj .getJSONObject ("up" );
4241
43- String [] upDomainTags = new String []{"acc" , "src" , "old_acc" , "old_src" };
44- for (String tag : upDomainTags ) {
45- JSONObject tagRootObj = upObj .getJSONObject (tag );
46- JSONArray tagMainObj = tagRootObj .getJSONArray ("main" );
47- for (int i = 0 ; i < tagMainObj .length (); i ++) {
48- String upDomain = tagMainObj .getString (i );
49- domainsList .add (upDomain );
50- domainsMap .put (upDomain , 0L );
51- }
42+ JSONArray hostsJson = obj .optJSONArray ("hosts" );
43+
44+ if (hostsJson == null || hostsJson .length () == 0 ){
45+ return new ZoneInfo (0 , domainsList , domainsMap );
46+ }
5247
53- try {
54- JSONArray tagBackupObj = tagRootObj .getJSONArray ("backup" );
55- if (tagBackupObj != null ) {
56- //this backup tag is optional
57- for (int i = 0 ; i < tagBackupObj .length (); i ++) {
58- String upHost = tagBackupObj .getString (i );
59- domainsList .add (upHost );
60- domainsMap .put (upHost , 0L );
48+ JSONObject regionJson = hostsJson .optJSONObject (0 );
49+
50+ int ttl = regionJson .optInt ("ttl" );
51+ JSONObject upObj = regionJson .optJSONObject ("up" );
52+
53+ String [] upDomainTags = new String []{"domains" , "old" };
54+ for (String tag : upDomainTags ) {
55+ JSONArray tagObjects = upObj .optJSONArray (tag );
56+ if (tagObjects != null && tagObjects .length () > 0 ){
57+ for (int i = 0 ; i < tagObjects .length (); i ++) {
58+ String upDomain = tagObjects .optString (i );
59+ if (upDomain != null && upDomain .length () > 0 ){
60+ domainsList .add (upDomain );
61+ domainsMap .put (upDomain , 0L );
6162 }
6263 }
63- } catch (JSONException ex ) {
64- //some zone has not backup domain, just ignore here
6564 }
6665 }
66+
6767 return new ZoneInfo (ttl , domainsList , domainsMap );
6868 }
6969
0 commit comments