Search in sources :

Example 46 with Gson

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);
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson)

Example 47 with Gson

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);
}
Also used : Gson(com.google.gson.Gson)

Example 48 with Gson

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));
}
Also used : SinglePERequest(io.s4.message.SinglePERequest) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) GsonBuilder(com.google.gson.GsonBuilder) SinglePERequest(io.s4.message.SinglePERequest) Request(io.s4.message.Request) Type(java.lang.reflect.Type) InstanceCreator(com.google.gson.InstanceCreator) JsonObject(com.google.gson.JsonObject)

Example 49 with Gson

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);
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson) Parameter(com.github.scribejava.core.model.Parameter)

Example 50 with Gson

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"));
}
Also used : OAuth2AccessToken(com.github.scribejava.core.model.OAuth2AccessToken) Gson(com.google.gson.Gson) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1309 Test (org.junit.Test)280 HashMap (java.util.HashMap)227 GsonBuilder (com.google.gson.GsonBuilder)174 JsonObject (com.google.gson.JsonObject)157 IOException (java.io.IOException)147 CommandWrapper (ClientServerApi.CommandWrapper)123 ArrayList (java.util.ArrayList)121 CommandExecuter (CommandHandler.CommandExecuter)119 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)118 JsonSyntaxException (com.google.gson.JsonSyntaxException)103 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)96 JsonElement (com.google.gson.JsonElement)78 Type (java.lang.reflect.Type)77 Map (java.util.Map)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)53 SmartCode (BasicCommonClasses.SmartCode)50 InputStreamReader (java.io.InputStreamReader)49 List (java.util.List)49 TypeToken (com.google.gson.reflect.TypeToken)44