You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/12/24 12:04:12 UTC
(camel) 07/08: CAMEL-14028: Allow DataFormats to unmarshal known data formats without first converting to bytes
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch unmarshal
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0a92ec1c2241e53fd3cec609ecb0f136f79050d7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Dec 24 12:38:45 2023 +0100
CAMEL-14028: Allow DataFormats to unmarshal known data formats without first converting to bytes
---
.../camel/dataformat/flatpack/FlatpackDataFormat.java | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java b/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java
index c575e22cc34..1c9c09c07c9 100644
--- a/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java
+++ b/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java
@@ -22,6 +22,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
+import java.io.StringReader;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -110,7 +111,22 @@ public class FlatpackDataFormat extends ServiceSupport implements DataFormat, Da
@Override
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
- InputStreamReader reader = new InputStreamReader(stream, ExchangeHelper.getCharsetName(exchange));
+ return unmarshal(exchange, (Object) stream);
+ }
+
+ @Override
+ public Object unmarshal(Exchange exchange, Object body) throws Exception {
+ Reader reader;
+ if (body instanceof Reader r) {
+ reader = r;
+ } else if (body instanceof String s) {
+ reader = new StringReader(s);
+ } else {
+ // fallback to input stream
+ InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, exchange, body);
+ reader = new InputStreamReader(is, ExchangeHelper.getCharsetName(exchange));
+ }
+
try {
Parser parser = createParser(exchange, reader);
DataSet dataSet = parser.parse();