Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Cannot convert value [true] of type class java.lang.String to Object Array for field

avatar
Expert Contributor

Hello Team,

I have JSON like following

[
{
"INTEGRATION_ID": "1",
"ISSUE_STATUS_CAT": "Done",
"SPRINT_LIST": [
"24-w1-2",
"24-w1-3",
"24-w1-4"
]
},{

"INTEGRATION_ID": "2",
"ISSUE_STATUS_CAT": "Done",
"SPRINT_LIST": "24-w1-2"

}
]

My requirement is to check whether SPRINT_LIST is array or not. so I am using UpdateRecord processor with following formula 

${field.value:startsWith(" [ ")}

I was getting the correct output earlier, where it returned 'True' when the value was a list and 'False' when it was null or not a list. However, after making some changes and then reverting back to the original settings, I started encountering issues. "Cannot convert value [true] of type class java.lang.String to Object Array for field error"

Shakib M.
1 ACCEPTED SOLUTION

avatar

Hi,

It depends on how you are setting the UpdateRecord processor. If you can provide screenshot it will help us figure out the issue. It seems you are trying to overwrite the field SPRINT_LIST and its complaining that you cannot convert Array to String because its already an array in the first record. May I suggest a different approach because the UpdateRecord you have to worry about setting the Record Writer\Reader and also you have to define the avro schema accordingly if you are planning to add new fields. Instead you can just use the Json Jolt Transformation processor with the following spec:

 

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "SPRINT_LIST": {
          "0": {
            "#true": "[&3].is_sprint_array"
          },
          "@": "[&2].SPRINT_LIST"
        },
        "*": "[&1].&"
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "*": {
        "is_sprint_array": "false"
      }
    }
  }
]

No need to set record reader\writer as long you know the input is always its valid json and has same schema. This will give you the following output:

 

[ {
  "INTEGRATION_ID" : "1",
  "ISSUE_STATUS_CAT" : "Done",
  "SPRINT_LIST" : [ "24-w1-2", "24-w1-3", "24-w1-4" ],
  "is_sprint_array" : "true"
}, {
  "INTEGRATION_ID" : "2",
  "ISSUE_STATUS_CAT" : "Done",
  "SPRINT_LIST" : "24-w1-2",
  "is_sprint_array" : "false"
} ]

 

If that helps please accept solution.

Thanks

View solution in original post

2 REPLIES 2

avatar

Hi,

It depends on how you are setting the UpdateRecord processor. If you can provide screenshot it will help us figure out the issue. It seems you are trying to overwrite the field SPRINT_LIST and its complaining that you cannot convert Array to String because its already an array in the first record. May I suggest a different approach because the UpdateRecord you have to worry about setting the Record Writer\Reader and also you have to define the avro schema accordingly if you are planning to add new fields. Instead you can just use the Json Jolt Transformation processor with the following spec:

 

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "SPRINT_LIST": {
          "0": {
            "#true": "[&3].is_sprint_array"
          },
          "@": "[&2].SPRINT_LIST"
        },
        "*": "[&1].&"
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "*": {
        "is_sprint_array": "false"
      }
    }
  }
]

No need to set record reader\writer as long you know the input is always its valid json and has same schema. This will give you the following output:

 

[ {
  "INTEGRATION_ID" : "1",
  "ISSUE_STATUS_CAT" : "Done",
  "SPRINT_LIST" : [ "24-w1-2", "24-w1-3", "24-w1-4" ],
  "is_sprint_array" : "true"
}, {
  "INTEGRATION_ID" : "2",
  "ISSUE_STATUS_CAT" : "Done",
  "SPRINT_LIST" : "24-w1-2",
  "is_sprint_array" : "false"
} ]

 

If that helps please accept solution.

Thanks

avatar
Expert Contributor

Thank you @SAMSAL , I tried using JOLT, but when it didn't work, I resorted to using the UpdateRecords process. However, this is ultimately what I need.

Shakib M.