use of com.google.gson.Gson in project bigbluebutton by bigbluebutton.
the class Red5AppAdapter method roomDisconnect.
@Override
public void roomDisconnect(IConnection conn) {
log.info("BBB Screenshare roomDisconnect");
String connType = getConnectionType(Red5.getConnectionLocal().getType());
String connId = Red5.getConnectionLocal().getSessionId();
String meetingId = conn.getScope().getName();
String userId = getUserId();
app.userDisconnected(meetingId, userId);
Map<String, Object> logData = new HashMap<String, Object>();
logData.put("meetingId", getMeetingId());
logData.put("userId", userId);
logData.put("connType", connType);
logData.put("connId", connId);
logData.put("event", "user_leaving_bbb_screenshare");
logData.put("description", "User leaving BBB Screenshare.");
Gson gson = new Gson();
String logStr = gson.toJson(logData);
log.info("User leaving bbb-screenshare: data={}", logStr);
super.roomDisconnect(conn);
}
use of com.google.gson.Gson in project fastjson by alibaba.
the class TestChineseQuote method test_chinese_quote.
public void test_chinese_quote() throws Exception {
String text = "{\"name\":“tiny.luo”,\"school\":\"\"}";
Gson gson = new Gson();
User user = gson.fromJson(text, User.class);
}
use of com.google.gson.Gson in project core by s4.
the class ObjectBuilder method main.
public static void main(String[] argv) throws Exception {
ObjectBuilder b = new ObjectBuilder();
String s = "{a:5, b:100}";
Object out = b.fromJson(s, TEST.class);
System.out.println(out.toString());
TEST t = new TEST(1, 2);
System.out.println(b.toJson(t));
String[] query = { "name", "count", "freq" };
String[] target = { "ACDW", "11" };
io.s4.message.Request.ClientRInfo rinfo = new io.s4.message.Request.ClientRInfo();
rinfo.setRequesterUUID(UUID.randomUUID());
Request req = new io.s4.message.SinglePERequest(Arrays.asList(target), Arrays.asList(query), rinfo);
System.out.println(req.toString());
InstanceCreator<io.s4.message.Request.RInfo> infoCreator = new InstanceCreator<io.s4.message.Request.RInfo>() {
public io.s4.message.Request.RInfo createInstance(Type type) {
return new io.s4.message.Request.ClientRInfo();
}
};
Gson gson = (new GsonBuilder()).registerTypeAdapter(io.s4.message.Request.RInfo.class, infoCreator).registerTypeAdapter(Object.class, new ObjectTypeAdapter()).create();
System.out.println("gson: " + gson.toJson(req));
System.out.println("gson reversed: " + gson.fromJson(gson.toJson(req), SinglePERequest.class));
System.out.println(b.toJson(req));
System.out.println(b.toJson(Arrays.asList(query)));
System.out.println("----------------------------------------------");
ArrayList<SSTest> list = new ArrayList<SSTest>();
SSTest ss1 = new SSTest();
ss1.str = "list-element-1";
SSTest ss2 = new SSTest();
ss2.str = "list-element-2";
list.add(ss1);
list.add(ss2);
Map<String, Object> listmap = new HashMap<String, Object>();
listmap.put("ll", list);
MapTest mt = new MapTest();
mt.map = listmap;
Object listmapobj = listmap;
System.out.println("list: " + gson.toJson(list));
System.out.println("listmap: " + gson.toJson(listmap));
System.out.println("listmapobj: " + gson.toJson(listmapobj));
System.out.println("mapobject: " + gson.toJson(mt));
}
use of com.google.gson.Gson in project scribejava by scribejava.
the class OAuth20ServiceUnit method prepareRawResponse.
private String prepareRawResponse(OAuthRequest request) {
final Gson json = new Gson();
final Map<String, String> response = new HashMap<>();
response.put(OAuthConstants.ACCESS_TOKEN, TOKEN);
response.put(OAuthConstants.STATE, STATE);
response.put("expires_in", EXPIRES);
response.putAll(request.getHeaders());
response.putAll(request.getOauthParameters());
for (Parameter p : request.getBodyParams().getParams()) {
response.put("query-" + p.getKey(), p.getValue());
}
return json.toJson(response);
}
use of com.google.gson.Gson in project scribejava by scribejava.
the class OAuth20ServiceTest method shouldProduceCorrectRequestSync.
@Test
public void shouldProduceCorrectRequestSync() throws IOException, InterruptedException, ExecutionException {
final OAuth20Service service = new ServiceBuilder().apiKey("your_api_key").apiSecret("your_api_secret").build(new OAuth20ApiUnit());
final OAuth2AccessToken token = service.getAccessTokenPasswordGrant("user1", "password1");
final Gson json = new Gson();
assertNotNull(token);
final Map<String, String> map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType());
assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN));
assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE));
assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in"));
final String authorize = Base64Encoder.getInstance().encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()).getBytes(Charset.forName("UTF-8")));
assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER));
assertEquals("user1", map.get("query-username"));
assertEquals("password1", map.get("query-password"));
assertEquals("password", map.get("query-grant_type"));
}
Aggregations