public MessageHeaders toHeaders()

in spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/JacksonRocketMQHeaderMapper.java [108:147]


	public MessageHeaders toHeaders(Map<String, String> source) {
		final Map<String, Object> target = new HashMap<>();
		final Map<String, String> jsonTypes = decodeJsonTypes(source);
		source.forEach((key, value) -> {
			if (matches(key) && !(key.equals(JSON_TYPES))) {
				if (jsonTypes.containsKey(key)) {
					Class<?> type = Object.class;
					String requestedType = jsonTypes.get(key);
					boolean trusted = trusted(requestedType);
					if (trusted) {
						try {
							type = ClassUtils.forName(requestedType, null);
						}
						catch (Exception e) {
							log.error("Could not load class for header: " + key, e);
						}
					}

					if (trusted) {
						try {
							Object val = decodeValue(value, type);
							target.put(key, val);
						}
						catch (IOException e) {
							log.error("Could not decode json type: " + value
									+ " for key: " + key, e);
							target.put(key, value);
						}
					}
					else {
						target.put(key, new NonTrustedHeaderType(value, requestedType));
					}
				}
				else {
					target.put(key, value);
				}
			}
		});
		return new MessageHeaders(target);
	}