0

I need a dynamic filtering criteria for querying west webservices using post.

to give you an example.

{
  "fields": [
             "field":"firstName",
             "field":"lastName"
            ]
,
  "filters": 
           [
              filter{"field":"firstName",
                     "operation":"EQ",
                     "value":"FIRSTNAME"
                    },
              filter{"field":"LastName",
                     "operation":"LIKE",
                     "value":["FIRSTNAME"]
                    },
              filter{"field":"address",
                     "operation":"IN",
                     "value":["1","2","3","4"]
                    },
           ]
}

please observe for operation "EQ" , it has single string, for rest of the filters, you need a list

based on operation, i want the value to be either as List or single string, how to build this dynamically in java, is it possible.

2 Answers2

1

Yes, it is possible, but don't do this, ever (example solution).

Instead, design your input in a clear way, so the user knows that there is option to put multiple values there. Maybe name a field values or valueList?

Don't create custom adapters, factory registries or custom deserializers, just redesign. Also don't go in the opposite direction - that would be accepting a list even with EQ parameter where you only need one element, just to simplify model. It's easier to code, but the end user is confused.

Shadov
  • 5,421
  • 2
  • 19
  • 38
0

Got my own solution had a abstract class as filter , then added two filters classes for list and not list separately , works wonderfully