11package org .gitlab4j .api .models ;
22
33import java .io .Serializable ;
4+ import java .lang .reflect .Array ;
5+ import java .util .ArrayList ;
46import java .util .Date ;
57import java .util .HashMap ;
8+ import java .util .List ;
69import java .util .Map ;
710
811import org .gitlab4j .api .GitLabApiException ;
@@ -93,7 +96,7 @@ public Object addSetting(String setting, Object value) throws GitLabApiException
9396 public Object addSetting (Setting setting , Object value ) throws GitLabApiException {
9497
9598 if (value instanceof JsonNode ) {
96- value = jsonNodeToValue ((JsonNode )value );
99+ value = jsonNodeToValue ((JsonNode )value , setting );
97100 }
98101
99102 setting .validate (value );
@@ -113,7 +116,7 @@ public void clearSettings() {
113116 settings .clear ();
114117 }
115118
116- private Object jsonNodeToValue (JsonNode node ) {
119+ private Object jsonNodeToValue (JsonNode node , Setting setting ) {
117120
118121 Object value = node ;
119122 if (node instanceof NullNode ) {
@@ -129,14 +132,17 @@ private Object jsonNodeToValue(JsonNode node) {
129132 } else if (node instanceof DoubleNode ) {
130133 value = (float )((DoubleNode )node ).asDouble ();
131134 } else if (node instanceof ArrayNode ) {
132-
133- int numItems = node .size ();
134- String [] values = new String [numItems ];
135- for (int i = 0 ; i < numItems ; i ++) {
136- values [i ] = node .path (i ).asText ();
135+ if (node .isEmpty ()) {
136+ value = setting .emptyArrayValue ();
137+ } else {
138+ List <Object > values = new ArrayList <>(node .size ());
139+ node .forEach (element -> values .add (jsonNodeToValue (element , setting )));
140+ Class <?> type = values .get (0 ).getClass ();
141+ value = Array .newInstance (type , values .size ());
142+ for (int i = 0 ; i < values .size (); i ++) {
143+ Array .set (value , i , type .cast (values .get (i )));
144+ }
137145 }
138-
139- value = values ;
140146 }
141147
142148 return (value );
0 commit comments