Skip to content

Instantly share code, notes, and snippets.

@eugenp
Created October 12, 2011 22:31
Show Gist options
  • Select an option

  • Save eugenp/1282846 to your computer and use it in GitHub Desktop.

Select an option

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

eugenp commented Feb 14, 2012

Copy link
Copy Markdown
Author

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