kotwal-itpro opened a new pull request, #7993:
URL: https://github.com/apache/hop/pull/7993
Fixes #7990.
## Problem
For an incoming JSON payload such as `{"test": null}` with the `test` output
field declared as type `String`, the JSON Input transform emits the
four-character literal string `"null"` rather than a proper Hop null. This
diverges from every other type-coercion path in the transform, which treats
missing data as null. The reporter's screenshots on #7990 show exactly this — a
`null`-valued JSON column arrives in the output stream as the string `null`.
## Root cause
`RowOutputConverter.getStringValue()`. JsonPath (configured via
`JacksonJsonNodeJsonProvider` in `FastJsonReader`) parses a JSON `null` into a
Jackson `NullNode` — a non-null Java reference whose `toString()` returns the
string `"null"`. The existing switch matched `Map` and `TextNode` explicitly
but fell through to `jo.toString()` for `NullNode`, embedding the literal
`"null"` into the output row. Then `targetMeta.convertDataFromString("null",
...)` happily produced the four-character string on the pipeline.
## Fix
Detect Jackson `NullNode` and `MissingNode` explicitly via
`JsonNode.isNull()` and `JsonNode.isMissingNode()` and return Java `null` from
`getStringValue` in both cases so `convertDataFromString(null, ...)` produces a
proper Hop null. `MissingNode` is included for symmetry with the
JsonPath-returned-missing case even though the primary bug is triggered by
`NullNode`.
`getStringValue` is now package-private and `static` so
`RowOutputConverterTest` can exercise it without spinning up a transform
context. No other behavior changes: `Map`, `TextNode`, plain `String`, and
other `JsonNode` subtypes (`IntNode` etc.) continue to flow through their
existing branches unchanged.
## Test
Adds `RowOutputConverterTest` with seven focused cases:
- `getStringValue_nullNode_returnsNull` — the #7990 regression
- `getStringValue_missingNode_returnsNull` — the symmetric MissingNode case
- `getStringValue_javaNull_returnsNull` — plain Java `null` (regression)
- `getStringValue_textNode_returnsUnquotedText` — pre-existing TextNode
branch (regression)
- `getStringValue_plainString_isPassedThrough` — plain-String passthrough
(regression)
- `getStringValue_intNode_fallsThroughToToString` — non-Text non-null nodes
still fall through
- `getStringValue_map_isSerializedAsJson` — Map -> JSON string (regression)
## Verified locally
- `./mvnw test` on `plugins/transforms/json` — 117 tests, 0 failures, 0
errors
- `./mvnw spotless:apply` — no formatting changes needed
- Java 21 build
--
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]