Search in sources :

Example 96 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project databus by linkedin.

the class PhysicalSourceConfig method toString.

@Override
public String toString() {
    try {
        ObjectMapper mapper = new ObjectMapper();
        StringWriter writer = new StringWriter();
        mapper.writeValue(writer, this);
        JSONObject jsonObj = new JSONObject(writer.toString());
        //The getMethod on this _dbusEventBuffer should be only called by the ConfigLoader
        if (_dbusEventBuffer != null) {
            ObjectMapper mapperDbus = new ObjectMapper();
            StringWriter writerDbus = new StringWriter();
            mapperDbus.writeValue(writerDbus, _dbusEventBuffer);
            jsonObj.put("dbusEventBuffer", new JSONObject(writerDbus.toString()));
        } else
            jsonObj.put("dbusEventBuffer", JSONObject.NULL);
        return jsonObj.toString();
    } catch (Exception ex) {
        ex.printStackTrace();
        // Should never happen, but the ObjectMapper could throw an Exception.
        return super.toString();
    }
}
Also used : StringWriter(java.io.StringWriter) JSONObject(org.json.JSONObject) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 97 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project databus by linkedin.

the class PhysicalSourceConfig method fromString.

/**
   * Converse of toString; populate this object from the String
   * @throws IOException
   * @throws JsonMappingException
   * @throws JsonParseException
   */
public static PhysicalSourceConfig fromString(String str) throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    PhysicalSourceConfig config = mapper.readValue(str, PhysicalSourceConfig.class);
    return config;
}
Also used : ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 98 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project spring-security-oauth by spring-projects.

the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetAccessTokenFromJson.

@Test
public void testGetAccessTokenFromJson() throws Exception {
    final OAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
    requestFactory = new ClientHttpRequestFactory() {

        public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
            return new StubClientHttpRequest(new ObjectMapper().writeValueAsString(token));
        }
    };
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setAuthorizationCode("foo");
    resource.setAccessTokenUri("http://localhost/oauth/token");
    request.setPreservedState(new Object());
    setUpRestTemplate();
    assertEquals(token, provider.obtainAccessToken(resource, request));
}
Also used : ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) IOException(java.io.IOException) DefaultAccessTokenRequest(org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest) AccessTokenRequest(org.springframework.security.oauth2.client.token.AccessTokenRequest) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) HttpMethod(org.springframework.http.HttpMethod) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) DefaultAccessTokenRequest(org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest) Test(org.junit.Test)

Example 99 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project spring-security-oauth by spring-projects.

the class JsonSerializationTests method testDefaultDeserialization.

@Test
public void testDefaultDeserialization() throws Exception {
    String accessToken = "{\"access_token\": \"FOO\", \"expires_in\": 100, \"token_type\": \"mac\"}";
    OAuth2AccessToken result = new ObjectMapper().readValue(accessToken, OAuth2AccessToken.class);
    // System.err.println(result);
    assertEquals("FOO", result.getValue());
    assertEquals("mac", result.getTokenType());
    assertTrue(result.getExpiration().getTime() > System.currentTimeMillis());
}
Also used : ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 100 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project spring-security-oauth by spring-projects.

the class JsonSerializationTests method testDefaultSerialization.

@Test
public void testDefaultSerialization() throws Exception {
    DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("FOO");
    accessToken.setExpiration(new Date(System.currentTimeMillis() + 10000));
    String result = new ObjectMapper().writeValueAsString(accessToken);
    // System.err.println(result);
    assertTrue("Wrong token: " + result, result.contains("\"token_type\":\"bearer\""));
    assertTrue("Wrong token: " + result, result.contains("\"access_token\":\"FOO\""));
    assertTrue("Wrong token: " + result, result.contains("\"expires_in\":"));
}
Also used : Date(java.util.Date) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (org.codehaus.jackson.map.ObjectMapper)356 IOException (java.io.IOException)75 Test (org.junit.Test)58 JsonNode (org.codehaus.jackson.JsonNode)47 ArrayList (java.util.ArrayList)43 HashMap (java.util.HashMap)43 Test (org.testng.annotations.Test)37 Map (java.util.Map)33 List (java.util.List)25 StringWriter (java.io.StringWriter)22 File (java.io.File)21 JSONObject (org.json.JSONObject)18 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)15 Version (org.codehaus.jackson.Version)14 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 JsonFactory (org.codehaus.jackson.JsonFactory)13 JSONObject (org.codehaus.jettison.json.JSONObject)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)11