ramu11 commented on code in PR #25684:
URL: https://github.com/apache/camel/pull/25684#discussion_r3858869470


##########
components/camel-toon/src/main/java/org/apache/camel/dataformat/toon/ToonDataFormat.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dataformat.toon;
+
+import java.io.BufferedWriter;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.util.Locale;
+
+import dev.toonformat.jtoon.DecodeOptions;
+import dev.toonformat.jtoon.Delimiter;
+import dev.toonformat.jtoon.EncodeOptions;
+import dev.toonformat.jtoon.JToon;
+import dev.toonformat.jtoon.KeyFolding;
+import dev.toonformat.jtoon.PathExpansion;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.DataFormatContentTypeHeader;
+import org.apache.camel.spi.DataFormatName;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.Dataformat;
+import org.apache.camel.support.ExchangeHelper;
+import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.util.IOHelper;
+
+/**
+ * Marshal JSON-compatible Java values to TOON (Token-Oriented Object 
Notation) and unmarshal TOON back to Java objects
+ * using the <a href="https://github.com/toon-format/toon-java";>JToon</a> 
library.
+ */
+@Dataformat("toon")
+@Metadata(firstVersion = "4.23.0", title = "TOON")
+public class ToonDataFormat extends ServiceSupport
+        implements DataFormat, DataFormatName, DataFormatContentTypeHeader, 
CamelContextAware {
+
+    static final String CONTENT_TYPE = "text/toon";
+
+    private CamelContext camelContext;
+    @Metadata(description = "Number of spaces per indentation level.", 
defaultValue = "2", javaType = "java.lang.Integer")
+    private int indent = EncodeOptions.DEFAULT.indent();
+    @Metadata(description = "Delimiter used for tabular array rows and inline 
primitive arrays.",
+              defaultValue = "COMMA", enums = "COMMA,TAB,PIPE")
+    private String delimiter = Delimiter.COMMA.name();
+    @Metadata(description = "Whether to prefix array lengths with a hash 
marker so arrays render as hash-prefixed lengths instead of plain lengths.",
+              defaultValue = "false", javaType = "java.lang.Boolean")
+    private boolean lengthMarker = EncodeOptions.DEFAULT.lengthMarker();
+    @Metadata(description = "Whether to enable strict validation when 
unmarshalling TOON. When false, JToon uses best-effort parsing.",
+              defaultValue = "true", javaType = "java.lang.Boolean")
+    private boolean strict = DecodeOptions.DEFAULT.strict();
+    @Metadata(description = "Whether the data format should set the 
Content-Type header to text/toon when marshalling.",
+              defaultValue = "true", javaType = "java.lang.Boolean")
+    private boolean contentTypeHeader = true;
+
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    public String getDataFormatName() {
+        return "toon";
+    }
+
+    @Override
+    public void marshal(Exchange exchange, Object graph, OutputStream stream) 
throws Exception {
+        EncodeOptions options = encodeOptions();
+        String toon;
+        if (graph instanceof String json) {

Review Comment:
   Thanks for raising this. We did consider whether plain `String` bodies 
should be handled as TOON scalar values through a separate option.
   
   The current implementation intentionally treats `String` bodies as JSON 
input and uses `JToon.encodeJson()`, while non-String bodies follow the object 
encoding path. We have documented this behavior and added test coverage for 
invalid JSON strings.
   
   For this Preview implementation, we prefer to keep the API surface minimal 
rather than introduce an additional option to change the interpretation of 
`String` bodies. We agree this behavior may be surprising for Camel users, so 
it is explicitly documented. We can revisit an opt-in scalar-string option 
based on feedback from Preview users.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to