Skip to content

Instantly share code, notes, and snippets.

@eugenp
Created October 12, 2011 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eugenp/1282846 to your computer and use it in GitHub Desktop.
Save eugenp/1282846 to your computer and use it in GitHub Desktop.
Integration testing of a REST API - conversion utilities
public static < T >String convertResourceToJson( final T resource )
throws IOException{
Preconditions.checkNotNull( resource );
return new ObjectMapper().writeValueAsString( resource );
}
public static < T >T convertJsonToResource
( final String json, final Class< T > clazzOfResource ) throws IOException{
Preconditions.checkNotNull( json );
Preconditions.checkNotNull( clazzOfResource );
return new ObjectMapper().readValue( json, clazzOfResource );
}
@eugenp
Copy link
Author

eugenp commented Feb 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment