Best way to represent a Notes Document as JSON?

I have been playing around with getting a JSON representation of a Notes Document (its data, not the Java class) and I am not sure how to write RichText fields to the JSON. Honestly, I am not even sure if it is worth doing it because I originally just wanted access to general data in the document from places like SWT views and local Portlets. But I would like to know if there is a method of putting the RichText into JSON and then having a component recreate the RichText on the other end? I currently use the “getMIMEEntity().getContentAsText()” but that does not seem to handle all of the character cases.

So I thought I would post a question to everyone, how would you do it using the Notes Java API's?


//Code from my conversion job
NotesThread.sinitThread();

// Create the notes session
Session session = NotesFactory.createSessionWithFullAccess();
Database db = getDatabase(url, session);

if (db == null) return Status.OK_STATUS;

//Construct our JSON object
JSONObject jObj = new JSONObject();

Document doc = getDocument(db, url, session);

if (doc == null) return Status.OK_STATUS;

Vector v = doc.getItems();
Iterator iter = v.iterator();

//Fill in the JSON object
while(iter.hasNext()){
Item i = (Item)iter.next();

if (i instanceof RichTextItem){
RichTextItem rt = (RichTextItem)i;
jObj.put(i.getName(), rt.getMIMEEntity().getContentAsText());
}else{
jObj.put(i.getName(), i.getText());
}
}

Tags: : : :

Advertisements

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.