aoelvp94 commented on code in PR #77249:
URL: https://github.com/apache/airflow/pull/77249#discussion_r4659841833


##########
java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/JsonValue.kt:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.airflow.sdk.execution
+
+/**
+ * Checks that [value] can be stored as an XCom or task-state value, and 
returns
+ * it unchanged so later encoding matches the previous Jackson behaviour.
+ *
+ * [Frame] encodes a request by converting the message object to a map with
+ * Jackson. A Scala collection, `Option` or case class (none of which are
+ * `java.util.Map` / `java.util.Collection`) was stored as that object's bean
+ * properties, or as `{}` when it had none, and the task succeeded. This
+ * inspects the original value first, and rejects those Scala types and any
+ * other object Jackson would encode as `{}`. Java types that already encoded
+ * usefully (POJOs and Kotlin data classes with properties, records, enums,
+ * `java.time`, `Date`, `Optional`, and so on) still pass through.
+ *
+ * Nested values in a `Map`, `Collection` or array are checked the same way.
+ */
+internal fun jsonValue(value: Any?): Any? {
+  rejectUnsupportedXComValue(value)
+  return value
+}
+
+private fun rejectUnsupportedXComValue(value: Any?) {
+  when (value) {
+    null, is String, is Boolean, is Number -> return
+    is ByteArray ->
+      throw IllegalArgumentException(
+        "Airflow does not accept byte arrays because they are not JSON values. 
" +
+          "Encode the bytes as a string first, for example with 
java.util.Base64.",
+      )
+    is Map<*, *> -> value.values.forEach(::rejectUnsupportedXComValue)
+    is Collection<*> -> value.forEach(::rejectUnsupportedXComValue)
+    is Array<*> -> value.forEach(::rejectUnsupportedXComValue)
+    is IntArray, is LongArray, is ShortArray, is DoubleArray, is FloatArray, 
is BooleanArray, is CharArray ->
+      return
+    else -> {
+      if (isScalaType(value.javaClass)) {
+        throw IllegalArgumentException(unsupportedScalaXComMessage(value))
+      }

Review Comment:
   Agreed, the Scala branch is removed in 
[7dcdb207e4](https://github.com/apache/airflow/pull/77249/commits/7dcdb207e408f0dde9034dfb92dc073ab2b418eb).
 The only rule left is generic: an object Jackson finds no properties for fails 
with `IllegalArgumentException` (naming the class and its path) instead of 
being stored as `{}`.
   
   It is a 
[`BeanSerializerModifier`](https://github.com/aoelvp94/airflow/blob/7dcdb207e408f0dde9034dfb92dc073ab2b418eb/java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Frame.kt#L192-L220)
 rather than `FAIL_ON_EMPTY_BEANS`, because that feature only fires for classes 
without annotations. On 1.0.0 an empty plain Java class already fails with 
Jackson's "No serializer found" message, but every Scala class carries 
`@ScalaSignature` and every Kotlin class `@Metadata`, so an empty case class 
was silently written as `{}`.



-- 
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