@@ -65,10 +65,22 @@ public boolean isObject() {
6565 return true ;
6666 }
6767
68- public AbstractObject object () {
68+ public AbstractObject object (boolean strict ) throws AbstractCoercingException {
6969 return this ;
7070 }
7171
72+ public AbstractArray array (boolean strict ) throws AbstractCoercingException {
73+ if (strict )
74+ throw new AbstractCoercingException (Type .ARRAY , Type .OBJECT );
75+ AbstractArray array = new AbstractArray ();
76+ for (int i = 0 ; i < size (); i ++) {
77+ if (!has (String .valueOf (i )))
78+ throw new AbstractCoercingException (Type .ARRAY , this );
79+ array .add (get (String .valueOf (i )));
80+ }
81+ return array ;
82+ }
83+
7284 public AbstractElement get (String key ) {
7385 return entries .get (key );
7486 }
@@ -91,6 +103,8 @@ public AbstractElement query(String query) {
91103 }
92104
93105 public AbstractElement query (String query , AbstractElement orElse ) {
106+ if (orElse == null )
107+ orElse = AbstractNull .VALUE ;
94108 AbstractElement value = query (query );
95109 return (value != null && !value .isNull ()) ? value : orElse ;
96110 }
@@ -127,18 +141,6 @@ public int size() {
127141 return entries .size ();
128142 }
129143
130- public AbstractArray array (boolean strict ) throws AbstractCoercingException {
131- if (strict )
132- throw new AbstractCoercingException (Type .ARRAY , Type .OBJECT );
133- AbstractArray array = new AbstractArray ();
134- for (int i = 0 ; i < size (); i ++) {
135- if (!has (String .valueOf (i )))
136- throw new AbstractCoercingException (Type .ARRAY , this );
137- array .add (get (String .valueOf (i )));
138- }
139- return array ;
140- }
141-
142144 public AbstractObject object (String key ) throws AbstractCoercingException {
143145 return query (key , AbstractNull .VALUE ).object ();
144146 }
@@ -168,23 +170,23 @@ public String string(String key) throws AbstractCoercingException {
168170 }
169171
170172 public String string (String key , String orElse ) throws AbstractCoercingException {
171- return query (key , new AbstractPrimitive (orElse )).string ();
173+ return query (key , orElse == null ? AbstractNull . VALUE : new AbstractPrimitive (orElse )).string ();
172174 }
173175
174176 public Boolean bool (String key ) throws AbstractCoercingException {
175177 return query (key , AbstractNull .VALUE ).bool ();
176178 }
177179
178180 public Boolean bool (String key , Boolean orElse ) throws AbstractCoercingException {
179- return query (key , new AbstractPrimitive (orElse )).bool ();
181+ return query (key , orElse == null ? AbstractNull . VALUE : new AbstractPrimitive (orElse )).bool ();
180182 }
181183
182184 public Number number (String key ) throws AbstractCoercingException {
183185 return query (key , AbstractNull .VALUE ).number ();
184186 }
185187
186188 public Number number (String key , Number orElse ) throws AbstractCoercingException {
187- return query (key , new AbstractPrimitive (orElse )).number ();
189+ return query (key , orElse == null ? AbstractNull . VALUE : new AbstractPrimitive (orElse )).number ();
188190 }
189191
190192 public Object toObject () {
0 commit comments