Through JSON converter i made the following wrapper class:

public class SmartlyStreetApex {

    public class Components {
        public String primary_number;
        public String street_predirection;
        public String street_name;
        public String street_suffix;
        public String city_name;
        public String default_city_name;
        public String state_abbreviation;
        public String zipcode;
        public String plus4_code;
        public String delivery_point;
        public String delivery_point_check_digit;

    public Integer input_index;
    public Integer candidate_index;
    public String delivery_line_1;
    public String last_line;
    public String delivery_point_barcode;
    public Components components;
    public Metadata metadata;
    public Analysis analysis;

    public class Analysis {
        public String dpv_match_code;
        public String dpv_footnotes;
        public String dpv_cmra;
        public String dpv_vacant;
        public String active;

    public class Metadata {
        public String record_type;
        public String zip_type;
        public String county_fips;
        public String county_name;
        public String carrier_route;
        public String congressional_district;
        public String rdi;
        public String elot_sequence;
        public String elot_sort;
        public Double latitude;
        public Double longitude;
        public String precision;
        public String time_zone;
        public Integer utc_offset;
        public Boolean dst;

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

And I am running execute anonymous code to execute

Http http = new Http();
HttpRequest request = new HttpRequest();
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200)
    SmartlyStreetApex result= SmartlyStreetApex.parse(response.getBody());

I am getting below error-

Line: 9, Column: 22 Illegal assignment from List to SmartlyStreetApex

Can someone check this please?


The return value is a list, so you need to use that same type:

List<SmartlyStreetApex> result= SmartlyStreetApex.parse(response.getBody());

Or, as I prefer, the shorter syntax:

SmartlyStreetApex[] result= SmartlyStreetApex.parse(response.getBody());
  • The first one I used thanks for this I also added this :) – psalesforce1989 Apr 6 '20 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.