-1
    {
      "columnreq": [
        {
          "column": "date",
          "datatype": "string"
        },
        {"column": "name",
          "datatype": "int"
        }
      ],
      "databaseName": "test",
      "sourceTableName": "department"
    }

I want to read the values using jackson and get the values of column and datatype in single variables with variable names as column and datatype in a list or a map.

zmerr
  • 534
  • 3
  • 18
Debashish Das
  • 69
  • 1
  • 5
  • 1
    There is plenty of documentation on this. What have you tried? What specific problem are you having? – Tim Aug 20 '21 at 09:50

1 Answers1

1

Json serialization libraries always pick the name before : as the variable name and whatever written after : as the value of it.

You can write:

case class Column (column: String, dataType: String)

case class MyContainer(columnReq: List[Column], databaseName: String, sourceTableName: String)

or if you want to further process it after writing it this way, you can write:

val container: MyContainer = parseJson(myJsonString) 

case class ModifiedContainer(Map[String, String], databaseName: String, sourceTableName: String)

ModifiedContainer(
   container.columnReq.map(column => (column.column, column.dataType)).toMap,
 container.databaseName,
 container.sourceTableName
)
zmerr
  • 534
  • 3
  • 18