File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed
main/java/io/avaje/json/node
test/java/io/avaje/json/node Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -83,4 +83,32 @@ public JsonArray add(JsonNode element) {
83
83
return this ;
84
84
}
85
85
86
+ /**
87
+ * Add a String value.
88
+ */
89
+ public JsonArray add (String value ) {
90
+ return add (JsonString .of (value ));
91
+ }
92
+
93
+ /**
94
+ * Add a boolean value.
95
+ */
96
+ public JsonArray add (boolean value ) {
97
+ return add (JsonBoolean .of (value ));
98
+ }
99
+
100
+ /**
101
+ * Add a int value.
102
+ */
103
+ public JsonArray add (int value ) {
104
+ return add (JsonInteger .of (value ));
105
+ }
106
+
107
+ /**
108
+ * Add a long value.
109
+ */
110
+ public JsonArray add (long value ) {
111
+ return add (JsonLong .of (value ));
112
+ }
113
+
86
114
}
Original file line number Diff line number Diff line change @@ -69,4 +69,22 @@ void text() {
69
69
assertThat (JsonArray .create ().text ()).isEqualTo ("[]" );
70
70
assertThat (basicArray .text ()).isEqualTo ("[42, foo]" );
71
71
}
72
+
73
+ @ Test
74
+ void add () {
75
+ JsonArray array = JsonArray .create ()
76
+ .add ("string" )
77
+ .add (1 ).add (99L )
78
+ .add (true )
79
+ .add (JsonObject .create ());
80
+
81
+ List <JsonNode > elements = array .elements ();
82
+ assertThat (elements ).hasSize (5 );
83
+ assertThat (elements .get (0 )).isInstanceOf (JsonString .class );
84
+ assertThat (elements .get (1 )).isInstanceOf (JsonInteger .class );
85
+ assertThat (elements .get (2 )).isInstanceOf (JsonLong .class );
86
+ assertThat (elements .get (3 )).isInstanceOf (JsonBoolean .class );
87
+ assertThat (elements .get (4 )).isInstanceOf (JsonObject .class );
88
+ }
89
+
72
90
}
Original file line number Diff line number Diff line change @@ -98,8 +98,8 @@ void create_JsonString_expect_sameInstance() {
98
98
@ Test
99
99
void arrayCreateOfMixed_defaultStream () {
100
100
JsonArray jsonArray = JsonArray .create ()
101
- .add (JsonInteger . of ( 42 ) )
102
- .add (JsonString . of ( "foo" ) );
101
+ .add (42 )
102
+ .add ("foo" );
103
103
104
104
var asJson = node .toJson (jsonArray );
105
105
assertThat (asJson ).isEqualTo ("[42,\" foo\" ]" );
You can’t perform that action at this time.
0 commit comments