7777import org .springframework .messaging .converter .MessageConverter ;
7878import org .springframework .messaging .converter .StringMessageConverter ;
7979import org .springframework .stereotype .Component ;
80+ import org .springframework .util .Assert ;
8081import org .springframework .util .ClassUtils ;
8182import org .springframework .util .CollectionUtils ;
8283import org .springframework .util .InvalidMimeTypeException ;
8384import org .springframework .util .MimeType ;
8485import org .springframework .util .StringUtils ;
8586
87+
8688/**
8789 * @author Dave Syer
8890 * @author Mark Fisher
@@ -212,10 +214,10 @@ public static class JsonMapperConfiguration {
212214 public JsonMapper jsonMapper (ApplicationContext context ) {
213215 String preferredMapper = context .getEnvironment ().getProperty (JSON_MAPPER_PROPERTY );
214216 if (StringUtils .hasText (preferredMapper )) {
215- if ("gson" .equals (preferredMapper ) && ClassUtils . isPresent ( "com.google.gson.Gson" , null ) ) {
217+ if ("gson" .equals (preferredMapper )) {
216218 return gson (context );
217219 }
218- else if ("jackson" .equals (preferredMapper ) && ClassUtils . isPresent ( "com.fasterxml.jackson.databind.ObjectMapper" , null ) ) {
220+ else if ("jackson" .equals (preferredMapper )) {
219221 return jackson (context );
220222 }
221223 }
@@ -231,6 +233,8 @@ else if (ClassUtils.isPresent("com.google.gson.Gson", null)) {
231233 }
232234
233235 private JsonMapper gson (ApplicationContext context ) {
236+ Assert .state (ClassUtils .isPresent ("com.google.gson.Gson" , ClassUtils .getDefaultClassLoader ()),
237+ "Can not bootstrap Gson mapper since Gson is not on the classpath" );
234238 Gson gson ;
235239 try {
236240 gson = context .getBean (Gson .class );
@@ -243,6 +247,8 @@ private JsonMapper gson(ApplicationContext context) {
243247
244248 @ SuppressWarnings ("unchecked" )
245249 private JsonMapper jackson (ApplicationContext context ) {
250+ Assert .state (ClassUtils .isPresent ("com.fasterxml.jackson.databind.ObjectMapper" , ClassUtils .getDefaultClassLoader ()),
251+ "Can not bootstrap Jackson mapper since Jackson is not on the classpath" );
246252 ObjectMapper mapper ;
247253 try {
248254 mapper = context .getBean (ObjectMapper .class ).copy ();
@@ -274,7 +280,7 @@ private JsonMapper jackson(ApplicationContext context) {
274280 return new JacksonMapper (mapper );
275281 }
276282
277- private static String getConfigDetails (ObjectMapper mapper ) {
283+ private String getConfigDetails (ObjectMapper mapper ) {
278284 StringBuilder sb = new StringBuilder ();
279285
280286 sb .append ("Modules:\n " );
0 commit comments