Java: Simplify Map based on attributes defined in expressions

35 Views Asked by At

I have a Map structure that I need to simplify. Based on a list of expressions I should produce another Map containing only the matching entries in the Map. The map is a multilevel structure and the expressions are MvEL ones.

Map:

{
  "job": {
    "job_id": "1", 
    "customer": "customer_1", 
    "total_cost": 2000,
    "job_details": [
      {
        "job_detail_id": "1",
        "address": "123 Downtown", 
        "cost": 200,
        "type": "cleaning" 
      },
      {
        "job_detail_id": "2",
        "address": "123 Faraway", 
        "cost": 1200,
        "type": "tiling" 
      }
    ]
  }
}

Expressions:

[
  job.job_id,
  job.job_details.job_detail_id,
  job.job_details.type
]

Result expected:

{
  "job": {
    "job_id": "1",
    "job_details": [
      {
        "job_detail_id": "1",
        "type": "cleaning" 
      },
      {
        "job_detail_id": "2",
        "type": "tiling" 
      }
    ]
  }
}

I have been experimenting with MvEL but have not been able to find a way to do this. Any help will be most appreciated.

0

There are 0 best solutions below