spring-geode/src/main/java/org/springframework/geode/data/json/converter/support/JacksonJsonToPdxConverter.java
/**
	 * Converts the given {@link String JSON} containing multiple objects into an array of {@link PdxInstance} objects.
	 *
	 * @param json {@link String JSON} data to convert.
	 * @return an array of {@link PdxInstance} objects from the given {@link String JSON}.
	 * @throws IllegalStateException if the {@link String JSON} does not start with
	 * either a JSON array or a JSON object.
	 * @see org.apache.geode.pdx.PdxInstance
	 */
Converts the given  String JSON containing multiple objects into an array of  PdxInstance objects.
@param json  String JSON data to convert.
@return an array of  PdxInstance objects from the given  String JSON.
@throws IllegalStateException if the  String JSON does not start with
either a JSON array or a JSON object.
Converts the given String JSON containing multiple objects into an array of PdxInstance objects . @param json String JSON data to convert . @return an array of PdxInstance objects from the given String JSON . @throws IllegalStateException if the String JSON does not start with either a JSON array or a JSON object .
@Nullable @Override
	public PdxInstance[] convert(String json) {
		try {
			JsonNode jsonNode = getObjectMapper().readTree(json);
			List<PdxInstance> pdxList = new ArrayList<>();
			if (isArray(jsonNode)) {
				ArrayNode arrayNode = (ArrayNode) jsonNode;
				JsonToPdxConverter converter = getJsonToPdxConverter();
				for (JsonNode object : asIterable(CollectionUtils.nullSafeIterator(arrayNode.elements()))) {
					pdxList.add(converter.convert(object.toString()));
				}
			}
			else if (isObject(jsonNode)) {
				ObjectNode objectNode = (ObjectNode) jsonNode;
				pdxList.add(getJsonToPdxConverter().convert(objectNode.toString()));
			}
			else {
				String message = String.format("Unable to process JSON node of type [%s];"
					+ " expected either an [%s] or an [%s]", jsonNode.getNodeType(),
						JsonNodeType.OBJECT, JsonNodeType.ARRAY);
				throw new IllegalStateException(message);
			}
			return pdxList.toArray(new PdxInstance[0]);
		}
		catch (JsonProcessingException cause) {
			throw new DataRetrievalFailureException("Failed to read JSON content", cause);
		}
	}
@ Nullable @ Override public PdxInstance [ ] convert ( String json ) { try { JsonNode jsonNode = getObjectMapper ( ) . readTree ( json ) ; List < PdxInstance > pdxList = new ArrayList < > ( ) ; if ( isArray ( jsonNode ) ) { ArrayNode arrayNode = ( ArrayNode ) jsonNode ; JsonToPdxConverter converter = getJsonToPdxConverter ( ) ; for ( JsonNode object : asIterable ( CollectionUtils . nullSafeIterator ( arrayNode . elements ( ) ) ) ) { pdxList . add ( converter . convert ( object . toString ( ) ) ) ; } } else if ( isObject ( jsonNode ) ) { ObjectNode objectNode = ( ObjectNode ) jsonNode ; pdxList . add ( getJsonToPdxConverter ( ) . convert ( objectNode . toString ( ) ) ) ; } else { String message = String . format ( "Unable to process JSON node of type [%s];" + " expected either an [%s] or an [%s]" , jsonNode . getNodeType ( ) , JsonNodeType . OBJECT , JsonNodeType . ARRAY ) ; throw new IllegalStateException ( message ) ; } return pdxList . toArray ( new PdxInstance [ 0 ] ) ; } catch ( JsonProcessingException cause ) { throw new DataRetrievalFailureException ( "Failed to read JSON content" , cause ) ; } }
Converts the given {@link String JSON} containing multiple objects into an array of {@link PdxInstance} objects.
Converts the given { @link String JSON } containing multiple objects into an array of { @link PdxInstance } objects .