com.causecode.marshaller.BlogDomainMarshaller.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of content Show documentation
Show all versions of content Show documentation
A plugin used to manage contents like static pages, menus etc. at one place.
Also provides shortened and user friendly urls.
/*
* Copyright (c) 2011, CauseCode Technologies Pvt Ltd, India.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are not permitted.
*/
package com.causecode.marshaller
import grails.converters.JSON
import org.grails.web.converters.exceptions.ConverterException
import org.grails.web.converters.marshaller.ObjectMarshaller
import org.grails.web.json.JSONWriter
import com.causecode.content.blog.Blog
/**
* This is Blog domain Marshaller.
*/
class BlogDomainMarshaller implements ObjectMarshaller {
@Override
boolean supports(Object object) {
return Blog.isCase(object)
}
@Override
void marshalObject(Object object, JSON converter) throws ConverterException {
Blog blogInstance = object as Blog
String author = blogInstance.resolveAuthor()
JSONWriter writer = converter.writer
writer.object()
writer.key('id')
.value(blogInstance.id)
writer.key('title')
.value(blogInstance.title)
writer.key('subTitle')
.value(blogInstance.subTitle)
writer.key('body')
.value(blogInstance.body)
writer.key('author')
.value(author)
writer.key('publish')
.value(blogInstance.publish)
writer.key('blogImgSrc')
.value(blogInstance.blogImg?.path)
writer.key('dateCreated')
converter.convertAnother(blogInstance.dateCreated)
writer.key('lastUpdated')
converter.convertAnother(blogInstance.lastUpdated)
writer.key('publishedDate')
converter.convertAnother(blogInstance.publishedDate)
writer.key('type')
.value(blogInstance.contentType?.name())
writer.endObject()
}
}