List of usage examples for org.springframework.data.couchbase.core.mapping CouchbaseList CouchbaseList
public CouchbaseList()
From source file:org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService.java
/** * Decode a JSON string into the {@link CouchbaseStorable} structure. * * @param source the source formatted document. * @param target the target of the populated data. * * @return the decoded structure.// w w w . ja v a2s. c o m */ @Override public final CouchbaseStorable decode(final Object source, final CouchbaseStorable target) { try { JsonParser parser = factory.createParser((String) source); while (parser.nextToken() != null) { JsonToken currentToken = parser.getCurrentToken(); if (currentToken == JsonToken.START_OBJECT) { return decodeObject(parser, (CouchbaseDocument) target); } else if (currentToken == JsonToken.START_ARRAY) { return decodeArray(parser, new CouchbaseList()); } else { throw new MappingException("JSON to decode needs to start as array or object!"); } } parser.close(); } catch (IOException ex) { throw new RuntimeException("Could not decode JSON", ex); } return target; }
From source file:org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService.java
/** * Helper method to decode an object recursively. * * @param parser the JSON parser with the content. * @param target the target where the content should be stored. * * @throws IOException/*w w w .jav a 2 s . co m*/ * @returns the decoded object. */ private CouchbaseDocument decodeObject(final JsonParser parser, final CouchbaseDocument target) throws IOException { JsonToken currentToken = parser.nextToken(); String fieldName = ""; while (currentToken != null && currentToken != JsonToken.END_OBJECT) { if (currentToken == JsonToken.START_OBJECT) { target.put(fieldName, decodeObject(parser, new CouchbaseDocument())); } else if (currentToken == JsonToken.START_ARRAY) { target.put(fieldName, decodeArray(parser, new CouchbaseList())); } else if (currentToken == JsonToken.FIELD_NAME) { fieldName = parser.getCurrentName(); } else { target.put(fieldName, decodePrimitive(currentToken, parser)); } currentToken = parser.nextToken(); } return target; }
From source file:org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService.java
/** * Helper method to decode an array recusrively. * * @param parser the JSON parser with the content. * @param target the target where the content should be stored. * * @throws IOException//w w w. j a v a 2 s. c om * @returns the decoded list. */ private CouchbaseList decodeArray(final JsonParser parser, final CouchbaseList target) throws IOException { JsonToken currentToken = parser.nextToken(); while (currentToken != null && currentToken != JsonToken.END_ARRAY) { if (currentToken == JsonToken.START_OBJECT) { target.put(decodeObject(parser, new CouchbaseDocument())); } else if (currentToken == JsonToken.START_ARRAY) { target.put(decodeArray(parser, new CouchbaseList())); } else { target.put(decodePrimitive(currentToken, parser)); } currentToken = parser.nextToken(); } return target; }