private Set<Class<?>> filterInputClasses(Set<Class<?>> referencedClasses) { Set<Class<?>> typesToUse = Sets.newHashSet(); for (Class<?> beanClass : referencedClasses) { if (beanClass.isEnum()) { typesToUse.add(beanClass); continue; } if (beanClass.equals(void.class)) { continue; } if (beanClass instanceof Class && beanClass.isEnum()) { typesToUse.add(beanClass); continue; } if (beanClass == URI.class) { continue; } // Classes directly passed in to typescript-generator need to be directly serializable, so filter out the ones that serializers // exist for. SerializationConfig serializationConfig = OBJECT_MAPPER.getSerializationConfig(); final JavaType simpleType = OBJECT_MAPPER.constructType(beanClass); try { final JsonSerializer<?> jsonSerializer = BeanSerializerFactory.instance.createSerializer(serializationConfig, simpleType, null); if (jsonSerializer == null || jsonSerializer instanceof BeanSerializer) { typesToUse.add(beanClass); } } catch(Exception e) { } } return typesToUse; }
@SuppressWarnings("unchecked") public StdEscapeHTMLSerializerProvider(SerializationConfig serializationConfig) throws JsonMappingException { super(serializationConfig, new StdSerializerProvider(), BeanSerializerFactory.instance); JsonSerializer stringEscapeHTMLSerializer = new StringEscapeHTMLSerializer(); _serializerCache.addAndResolveNonTypedSerializer(String.class, stringEscapeHTMLSerializer, this); JavaType javaType = TypeFactory.fromCanonical(String.class.getName()); _serializerCache.addAndResolveNonTypedSerializer(javaType, stringEscapeHTMLSerializer, this); }
/** * * @param jf JsonFactory to use: if null, a new {@link MappingJsonFactory} will be constructed * @param sp SerializerProvider to use: if null, a {@link StdSerializerProvider} will be constructed * @param dp DeserializerProvider to use: if null, a {@link StdDeserializerProvider} will be constructed * @param sconfig Serialization configuration to use; if null, basic {@link SerializationConfig} * will be constructed * @param dconfig Deserialization configuration to use; if null, basic {@link DeserializationConfig} * will be constructed */ public ObjectMapper(JsonFactory jf, SerializerProvider sp, DeserializerProvider dp, SerializationConfig sconfig, DeserializationConfig dconfig) { /* 02-Mar-2009, tatu: Important: we MUST default to using * the mapping factory, otherwise tree serialization will * have problems with POJONodes. * 03-Jan-2010, tatu: and obviously we also must pass 'this', * to create actual linking. */ _jsonFactory = (jf == null) ? new MappingJsonFactory(this) : jf; // visibility checker; usually default _visibilityChecker = STD_VISIBILITY_CHECKER; _serializationConfig = (sconfig != null) ? sconfig : new SerializationConfig(DEFAULT_INTROSPECTOR, DEFAULT_ANNOTATION_INTROSPECTOR, _visibilityChecker); _deserializationConfig = (dconfig != null) ? dconfig : new DeserializationConfig(DEFAULT_INTROSPECTOR, DEFAULT_ANNOTATION_INTROSPECTOR, _visibilityChecker); _serializerProvider = (sp == null) ? new StdSerializerProvider() : sp; _deserializerProvider = (dp == null) ? new StdDeserializerProvider() : dp; // Default serializer factory is stateless, can just assign _serializerFactory = BeanSerializerFactory.instance; // and use standard JsonNodeFactory initially _nodeFactory = JsonNodeFactory.instance; }