Search code examples
javascriptjavajsonjackson-databind

Is there a way for com.fasterxml.jackson.databind.ObjectMapper to process JavaScript Object?


We have an existing function that uses com.fasterxml.jackson.databind.ObjectMapper and formats the following JSON as com.fasterxml.jackson.databind.JsonNode.

{
  "headerName": "Column1",
  "field": "COLUMN1",
}

All good and it is working as expected. Now, we want to introduce events handling. To do that, we need to add a property in the JSON that makes it no longer a JSON but a JavaScript Object. Example below.

{
  "headerName": "Column1",
  "field": "COLUMN1",
  "onCellDoubleClicked": (event) => {
     this.onCellDoubleClicked(this, event, "COLUMN1");
   }
}

It is now throwing the following exception:

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('(' (code 40)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)" 

I checked if Chat GPT will be useful and I got the following message: enter image description here

Is there an alternative to com.fasterxml.jackson so I can process this JavaScript Object?


Solution

  • Had another thought about this. It is a bad idea to allow users to input functions because it will lead to security vulnerabilities.

    I ended up having flags instead.

    {
      "headerName": "Column1",
      "field": "COLUMN1",
      "openPopup": "true"
    }
    

    Depending on the flag passed, pre-defined functions will get triggered.