Example usage for org.springframework.data.couchbase.core.mapping CouchbaseDocument put

List of usage examples for org.springframework.data.couchbase.core.mapping CouchbaseDocument put

Introduction

In this page you can find the example usage for org.springframework.data.couchbase.core.mapping CouchbaseDocument put.

Prototype

public final CouchbaseDocument put(final String key, final Object value) 

Source Link

Document

Store a value with the given key for later retreival.

Usage

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/*from  w  w  w. j a va  2  s  .  c  om*/
 * @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;
}