All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.causecode.marshaller.BlogDomainMarshaller.groovy Maven / Gradle / Ivy

Go to download

A plugin used to manage contents like static pages, menus etc. at one place. Also provides shortened and user friendly urls.

There is a newer version: 2.6.2
Show newest version
/*
 * 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()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy