REST - Same TAG different Type


Im try integrate Redmine Rest Api and in the response im have 2 different types in the same block for field value.


"custom_fields": [
          "id": 7,
          "name": "Cliente",
          "value": "Alcon"

          "id": 44,
          "name": "Produto",
          "multiple": true,
          "value": [


So my structure Data Type for field value change, same time is text same time is Text List, and im get erro.


Rafael Freitas


Hello Rafael,

This is a problem with REST API, as there is no "formal contract". While I think exposing a REST webserver that can change the Data Type for the same attribute is very bad practice, this happens a lot.

In general, to solve this, what you do is to use the OnAfterResponse to manipulate the response before it is delivered as a structure/list.

In your case, I would say that you must discover what data types are possible and change your structure to have all of them, and in the OnAfterResponse you manipulate the JSON changing the name of the attribute to match the correct type in the structure.

I know that it seems a lot of work, but I think this is the only way to do that (easily).