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();
}
}
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;
}
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));
}
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());
}
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\":"));
}
Aggregations