66import lombok .Getter ;
77import lombok .ToString ;
88import org .jetbrains .annotations .NotNull ;
9+ import org .jetbrains .annotations .Nullable ;
910import org .json .JSONObject ;
1011
1112import java .time .Instant ;
@@ -39,8 +40,8 @@ public class Plan {
3940 /**
4041 * The ip fallback number of the plan.
4142 */
42- @ Getter
43- private final int ipFallback ;
43+ @ Getter @ Nullable
44+ private final Integer ipFallback ;
4445
4546 /**
4647 * The type of ips of the plan.
@@ -69,8 +70,8 @@ public class Plan {
6970 /**
7071 * The number of new ips of the plan.
7172 */
72- @ Getter
73- private final int ips_new ;
73+ @ Getter @ Nullable
74+ private final Integer ips_new ;
7475
7576 /**
7677 * Constructor of the plan from the JSON object.
@@ -80,12 +81,20 @@ public Plan(@NotNull final JSONObject jsonObject) {
8081 this .start = Instant .parse (jsonObject .getString ("start" ));
8182 this .product = jsonObject .getString ("product" );
8283 this .type = Objects .requireNonNull (PlanType .fromString (jsonObject .getString ("type" )));
83- this .ipFallback = jsonObject .getInt ("ip_fallback" );
8484 this .ipsType = Objects .requireNonNull (IpType .fromString (jsonObject .getString ("ips_type" )));
8585 this .ips = jsonObject .getInt ("ips" );
8686 this .country = jsonObject .getString ("country" );
8787 this .bandwidth = jsonObject .getString ("bandwidth" );
88- this .ips_new = jsonObject .getInt ("ips_new" );
88+ // Ip fallback
89+ if (jsonObject .has ("ip_fallback" ))
90+ this .ipFallback = jsonObject .getInt ("ip_fallback" );
91+ else
92+ this .ipFallback = null ;
93+ // Ips new
94+ if (jsonObject .has ("ips_new" ))
95+ this .ips_new = jsonObject .getInt ("ips_new" );
96+ else
97+ this .ips_new = null ;
8998 }
9099
91100 /**
@@ -130,12 +139,12 @@ public Plan(@NotNull final Instant start,
130139 jsonObject .put ("start" , start .toString ());
131140 jsonObject .put ("product" , product );
132141 jsonObject .put ("type" , type .toString ());
133- jsonObject .put ("ip_fallback" , ipFallback );
142+ jsonObject .put ("ip_fallback" , ( ipFallback == null ) ? JSONObject . NULL : ipFallback );
134143 jsonObject .put ("ips_type" , ipsType .toString ());
135144 jsonObject .put ("ips" , ips );
136145 jsonObject .put ("country" , country );
137146 jsonObject .put ("bandwidth" , bandwidth );
138- jsonObject .put ("ips_new" , ips_new );
147+ jsonObject .put ("ips_new" , ( ips_new == null ) ? JSONObject . NULL : ips_new );
139148 return jsonObject ;
140149 }
141150
0 commit comments