protected override Message CreateMessage(object objectToConvert, MessageProperties messageProperties, Type genericType) { byte[] bytes; try { var jsonString = JsonConvert.SerializeObject(objectToConvert, Settings); bytes = DefaultCharset.GetBytes(jsonString); } catch (Exception e) { throw new MessageConversionException("Failed to convert Message content", e); } messageProperties.ContentType = SupportedContentType.ToString(); messageProperties.ContentEncoding = EncodingUtils.GetEncoding(DefaultCharset); messageProperties.ContentLength = bytes.Length; // var type = genericType == null ? objectToConvert.GetType() : genericType; // if (genericType != null && !type.isContainerType() // && Modifier.isAbstract(type.getRawClass().getModifiers())) // { // type = this.objectMapper.constructType(objectToConvert.getClass()); // } // FromType(type, messageProperties); return(new Message(bytes, messageProperties)); }
private bool TryGetOpenApiMediaType(IDictionary<string, OpenApiMediaType> contentTypes, SupportedContentType contentType, out OpenApiMediaType mediaType, out string detectedContentType) { var contentTypesIgnoreCase = new Dictionary<string, OpenApiMediaType>(contentTypes, StringComparer.InvariantCultureIgnoreCase); string contentDescription = contentType.GetDescription(); if (contentTypesIgnoreCase.TryGetValue(contentDescription, out mediaType)) { detectedContentType = contentDescription; return true; } var key = contentTypesIgnoreCase.Keys.FirstOrDefault(ct => ct.Contains(contentDescription)); if (key != null) { mediaType = contentTypesIgnoreCase[key]; detectedContentType = key; return true; } //if (contentTypesIgnoreCase.Count > 0) //{ // mediaType = contentTypesIgnoreCase.First().Value; // return true; //} detectedContentType = null; return false; }