[SalesForce] Convert JSON Array into Wrapper class in Salesforce

In certain callout I want to send JSON Array in following format. And based on this I want to parse this into doPost method and generate a dynamic query to query on Account object. But, I cannot access the List of Country into doPost method from wrapper class.

JSON Format I have to send:

{

"country":[ "IN", "PH", "KR" ], "Type":[ "Installation Partner",
"Technology Partner"], "industry":[ "Energy", "Education" ]

}

The Wrapper class I have written:

public class accountforPostRequestWrapper {

    public List<String> country{get; set;}
    public List<String> Type{get; set;}
    public List<String> industry{get; set;}

    public static List<accountforPostRequestWrapper> parse(String json){
         return (List<accountforPostRequestWrapper>) System.JSON.deserialize(json, List<accountforPostRequestWrapper>.class);
    }

}

Am I missing something.
In RestResource Class I have write something like below.

but its throwing error:

"Variable does not exist: country"

global with sharing class AccountResource {
@HttpPost
global static void doPost() {
    RestRequest req = RestContext.request;
    Blob body = req.requestBody;
    String jsonString = body.toString();

    List<String> listofCountry = new List<String>();
    listofCountry.clear();

    List<accountforPostRequestWrapper> accWr = accountforPostRequestWrapper.parse(jsonString);
    listofCountry.addAll(accWr.country);

    // In Above line this giving ERROR: "Variable does not exist: country"

    //Generate dynamic SOQL based on JSON Input       
    String searchStr = 'SELECT Id,Name,Industry,Type,Country_code__c FROM Account WHERE';
    String conditionStr = 'Country_code__c =: null';
    if(!accWr.isEmpty()){
            //to generate dynamic conditionStr here based on 
            //   country,Type, and industry value
        }
    }
}

Please help me how to parse this kind of JSON and how to fetch value from wrapper class and to generate the dynamic query considering null as well. Scenario is possible also that JSON contains no country, but has Type and industry. Please help.

Best Answer

Problem is accWr is declared as a List.

parse method must return an object:

public static AccountforPostRequestWrapper parse(String json){
     return (AccountforPostRequestWrapper) System.JSON.deserialize(json, AccountforPostRequestWrapper.class);
}

And your code would be as:

List<String> listofCountry = new List<String>();
listofCountry.clear();

AccountforPostRequestWrapper accWr = AccountforPostRequestWrapper.parse(jsonString);
listofCountry.addAll(accWr.country);