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

com.intellisrc.web.service.WebMessage.groovy Maven / Gradle / Ivy

Go to download

Create restful HTTP (GET, POST, PUT, DELETE, etc) or SSE / WebSocket application services. Manage JSON data from and to the server easily. It is build on top of Jetty library, so it is very powerful but designed to be elegant and easy to use.

The newest version!
package com.intellisrc.web.service

import com.intellisrc.etc.JSON
import groovy.transform.CompileStatic

/**
 * Simple class to convert data to String
 */
@CompileStatic
class WebMessage {
    protected final Map data
    protected final Class type
    WebMessage(Map data) {
        this.data = data
        type = Map
    }
    WebMessage(Collection data) {
        this.data = [ _data_ : data ]
        type = Collection
    }
    WebMessage(String data) {
        this.data = [ _data_ : data ]
        type = String
    }
    String toString() {
        return JSON.encode(type != Map ? data._data_ : data)
    }
    Map getData() {
        return type != Map ? [ data : data._data_ ] : data
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy