mercredi 25 février 2015

Create JSON data in the Couchbase Document by using Spring cache

I'm trying to convert Java object to Json object in the couchbase by using @Documents and @Field.


Here is the Java Object


@EqualsAndHashCode(includes = "stateCode, SubjectCode, year")


@Document class StandardsCollection extends VO implements Comparable {



@Field
String title;
@Field
String stateCode
@Field
String stateTitle
@Field
String subjectCode
@Field
String subjectTitle
@Field
Integer year
@Field
List<StandardsDocument> documents = []


/**
* @param docId the encryptedId of the desired document
* @return The StandardsDocument corresponding to the docId
*/
public StandardsDocument retrieveDocument(String docId) {
return this.documents.find {
docId == it.id
}
}


@Override
int compareTo(StandardsCollection o) {
return this?.title?.compareTo(o?.title)
}


}


In my xml configuration i used <couchbase:translation-service objectMapper="cachingCustomObjectMapper"></couchbase:translation-service>


And used @cacheable from spring cache to cache the method, when i see the Document in the couchbase it's in binary format instead i want that to be JSON format.



@Cacheable(value = "MusicStudioCache", key = "'spire/music/standardscollection/'+#stateCode+'/'+#subjectCode+'/'+#year")
public StandardsCollection findStandardsCollection(String stateCode, String subjectCode, Integer year) {
// Step 1: attempt to read object from couchB
// Step 2: if it fails, load object, store in cache, return object
return this.loadStandardsCollection(stateCode, subjectCode, year)
}


How to create this returned object to JSON in the couchbase?


Aucun commentaire:

Enregistrer un commentaire