Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
How to deserialize list with dynamic number of keys with same value structure?

I am trying to find an optimal way to deserialize dynamic fields that all contain the same value object structure:

"data": {
    "lastUpdate": 1605299294253,
    "tableData": [
        {
            "recordId": 1,
            "isSelected": 1,
            "myKey1": {
                "valueRef": 72,
                "value": "Some value"
            },
            "myKey2": {
                "valueRef": 0,
                "value": "123"
            }
        }
    ]
}

For the tableData JSON array, I have tried this approach without success:

import lombok.Data;
import java.util.Map;

@Data
public class TableRowDataVO {
    private Integer recordId;
    private Integer recordStatus;
    private Map<String, TableRowDetailVO> columnData1;
    private Map<String, TableRowDetailVO> columnData2;
}

This class is nested into another class to encompass the entire JSON body in data:

public class TabularDataDTO {
    private Long lastUpdate;
    private List<TableRowDataVO> tableData;
}

and each dynamic field holds the same Object of the following type:

public class TableRowDetailVO {
    private Integer valueRef;
    private String value;
}

There is also no guarantee that there are only 2 dynamic keys. It can be 0 to many dynamic keys that are in TableRowDataVO, but if there are limitations that require me to settle with 2, I can do that, but if 0 to many dynamic fields are possible, that would be great. I am trying to use the ObjectMapper with TypeReference as TabularDataVO but it throws an exception. What is the proper way to design my objects such that TabularDataVO can be deserialized by the mapper?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

since the key is dynamic so when you process data you need some special process.

@Data
public class NewDTO {
    private Long lastUpdate;
    private List<Map<String, Object>> tableData;
}
over 4 years ago · Santiago Trujillo Report

0

Just to understand your question correctly. You Json is like following: -

"data": {
    "lastUpdate": 1605299294253,
    "tableData": [
        {
            "recordId": 1,
            "isSelected": 1,
            "myKey1": {
                "valueRef": 72,
                "value": "Some value"
            },
            "myKey2": {
                "valueRef": 0,
                "value": "123"
            }
        }
    ]
}

Not like

"data": {
    "lastUpdate": 1605299294253,
    "tableData": [
        {
            "recordId": 1,
            "isSelected": 1,
            "keys": [
                 {
                   "valueRef": 72,
                   "value": "Some value"
                },
                {
                  "valueRef": 0,
                  "value": "123"
               }
           ]
        }
    ]
}

Latter can be easily deserialized using jackson library and defining keys as List<Map<String, Object>>

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!