/** * Helper method called when current token is no START_ARRAY. Will either throw an exception, or * try to handle value as if member of implicit array, depending on configuration. */ private final Collection<String> handleNonArray( JsonParser jp, DeserializationContext ctxt, Collection<String> result) throws IOException { // [JACKSON-526]: implicit arrays from single values? if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) { throw ctxt.mappingException(_collectionType.getRawClass()); } // Strings are one of "native" (intrinsic) types, so there's never type deserializer involved JsonDeserializer<String> valueDes = _valueDeserializer; JsonToken t = jp.getCurrentToken(); String value; if (t == JsonToken.VALUE_NULL) { value = (valueDes == null) ? null : valueDes.getNullValue(); } else { value = (valueDes == null) ? _parseString(jp, ctxt) : valueDes.deserialize(jp, ctxt); } result.add(value); return result; }
@Override public JSONArray deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JSONArray array = new JSONArray(); JsonToken t; while ((t = jp.nextToken()) != JsonToken.END_ARRAY) { switch (t) { case START_ARRAY: array.put(deserialize(jp, ctxt)); continue; case START_OBJECT: array.put(JSONObjectDeserializer.instance.deserialize(jp, ctxt)); continue; case VALUE_STRING: array.put(jp.getText()); continue; case VALUE_NULL: array.put(JSONObject.NULL); continue; case VALUE_TRUE: array.put(Boolean.TRUE); continue; case VALUE_FALSE: array.put(Boolean.FALSE); continue; case VALUE_NUMBER_INT: array.put(jp.getNumberValue()); continue; case VALUE_NUMBER_FLOAT: array.put(jp.getNumberValue()); continue; case VALUE_EMBEDDED_OBJECT: array.put(jp.getEmbeddedObject()); continue; } throw ctxt.mappingException("Urecognized or unsupported JsonToken type: " + t); } return array; }