commit | author | age
|
86bbf7
|
1 |
/* |
U |
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package de.uhilger.mediaz.api; |
|
7 |
|
|
8 |
import com.google.gson.Gson; |
|
9 |
|
|
10 |
/** |
|
11 |
* |
|
12 |
* @author ulrich |
|
13 |
*/ |
|
14 |
public class AbstractHandler { |
|
15 |
|
|
16 |
protected String jsonWithEnclosingType(Object o) { |
|
17 |
/* |
|
18 |
StringBuilder sb = new StringBuilder(); |
|
19 |
sb.append("{\""); |
|
20 |
sb.append(o.getClass().getSimpleName()); |
|
21 |
sb.append("\": "); |
|
22 |
Gson gson = new Gson(); |
|
23 |
sb.append(gson.toJson(o)); |
|
24 |
sb.append("}"); |
|
25 |
return sb.toString(); |
|
26 |
*/ |
|
27 |
return jsonWithCustomType(o, o.getClass().getSimpleName()); |
|
28 |
} |
|
29 |
|
|
30 |
protected String jsonWithCustomType(Object o, String typeName) { |
|
31 |
StringBuilder sb = new StringBuilder(); |
|
32 |
sb.append("{\""); |
|
33 |
sb.append(typeName); |
|
34 |
sb.append("\": "); |
|
35 |
Gson gson = new Gson(); |
|
36 |
sb.append(gson.toJson(o)); |
|
37 |
sb.append("}"); |
|
38 |
return sb.toString(); |
|
39 |
} |
|
40 |
|
|
41 |
} |