/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.uhilger.mediaz.api; import com.google.gson.Gson; /** * * @author ulrich */ public class JsonHelper { public String jsonWithEnclosingType(Object o) { /* StringBuilder sb = new StringBuilder(); sb.append("{\""); sb.append(o.getClass().getSimpleName()); sb.append("\": "); Gson gson = new Gson(); sb.append(gson.toJson(o)); sb.append("}"); return sb.toString(); */ return jsonWithCustomType(o, o.getClass().getSimpleName()); } public String jsonWithCustomType(Object o, String typeName) { StringBuilder sb = new StringBuilder(); sb.append("{\""); sb.append(typeName); sb.append("\": "); Gson gson = new Gson(); sb.append(gson.toJson(o)); sb.append("}"); return sb.toString(); } }