Loading attributes of cars and orders from JSON I am creating an application that deals with cars and orders. 

A order contains a car and other information (BUYER, OWNER, ...), which constructs an orderObject.

A car has around 80 different attributes (TYP_WHEEL, TYP_DOOR, QUANTITY_WHEELS, ...) for the different car-parts.

I get the car-attributes and their values from a JSON string and put them into a map named allCarAttributes.

The JSON has this structure:

result: 
    data[]:
        characteristics_0[]: …
            …
        characteristics_1[]: …
            …
            …
            …
        characteristics_N[]: …


Each characteristics-array contains some attributes:

"result": {
    "data": [
        {
            "characteristics": [
                {
                    "description": "Car ceiling color",
                    "id": "COL_CAR_CEILING",
                    "value": "F8",
                    "valueDescription": "F8 - White"
                },
                {
                    "description": "Color Car Finishes",
                    "id": "COL_CAR_ACCESSORIES",
                    "value": "T",
                    "valueDescription": "ST- Stainless Steel"
                },
                {
                    "description": "Car flooring color",
                    "id": "COL_CAR_FLOORING",
                    "value": "RD10",
                    "valueDescription": "RD10, grey"
                },
                (...)


Then I go through this map and based on the attribute name I set the respective value in the orderObject. 

My problem: 
Since the methods to set the values in the orderObject each have different names, I am not able to find a more efficient way than using a switch-case with 80 cases.

for (Map.Entry&lt;String, String&gt; attribute : allCarAttributes.entrySet()) {

        switch (attribute.getKey()) {
        case "TYP_DOOR":
            orderObject.setDoor(attribute.getValue());
            break;
        case "TYP_WHEEL":
            orderObject.setWheelType(attribute.getValue());
            break;
        case "QANTITY_WHEELS":
            orderObject.setWheelNumber(attribute.getValue());
            break;

        (...)

        default:
            break;
        }
    }


The orderObject-class simply has several fields and setters/getters for them:

private String car_width;
private String car_depth;
private String car_height;
private String car_weight;
(...)

public String getCar_width() {
    return car_width;
}

public void setCar_width(String car_width) {
    this.car_width = car_width;
}


How can I get rid of this huge switch-case?

Should I get rid of it at all? The switch-case works fine as it is, it is just very long and ugly.
This is the typical problem the relational community (relational databases) answers with OR-Mappings. As we do not have a relational datastructure more an object structure the mapping impedance is less but it remains.

But as we have to do a mapping it is not the question IF but the question WHERE the mapping is neccessary. Finally you have ALWAYS a big switch-case-statement. It may not be obvious and maybe it is not done all by yourself but there is no way around. You cannot escape the mapping but you can get help with it.

A pragmatic way would be to use the "org.json" API, Here is the Maven dependency:

&lt;dependency&gt;
    &lt;groupId&gt;org.json&lt;/groupId&gt;
    &lt;artifactId&gt;json&lt;/artifactId&gt;
    &lt;version&gt;1.5-20090211&lt;/version&gt;
&lt;/dependency&gt;


With this library your mapping will be a little be easier. You can parse the json string:

JSONObject carInfoAsJsonObject = new JSONObject(jsonString);


Then you can wrapp this JSONObject into your own object and have the getters returning their values directly from the JSONObject:

class OrderObject {
    public String getCar_width() {
        return carInfoAsJsonObject.getString("CAR_WIDTH");
    }
}


Here you do not have a switch-case have you? Of course you have. But it is hidden in the structure we chose and not formulated with the JAVA language element "switch-case".

Another way is to let a library make the mapping decision. A good library is "Jackson". Here is the Maven dependency:

&lt;dependency&gt;
    &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
    &lt;version&gt;1.9.13&lt;/version&gt;
&lt;/dependency&gt;


The Jackson way is "mapping by name"-convention. Your keys must be named like the attributes of your JAVA Object that should follow the bean convention.

The central clas is the ObjectMapper you have to instantiate:

ObjectMapper mapper = new ObjectMapper();


Then you may have the OrderObject attribute names synchronized:

class OrderObject {
    private String CAR_WIDTH;
    // getter and setter
}


After that you can instantiate an object of the type OrderObject:

OrderObject orderObject = objectMapper.readValue(carInfoAsJsonString, OrderObject.class);