Ismail Omar
Ismail Omar

Reputation: 11

The field JsonHttpParser.jsonFactory is not visible

Im developing an application that simply shows the nearby places to my location and i have implemented the map layout and got my location. i have used this blog http://ddewaele.blogspot.com/2011/05/introducing-google-places-api.html

in order to retrieve the places nearby but there is one problem i cant solve in this method

private static final HttpTransport transport = AndroidHttp .newCompatibleTransport(); public static HttpRequestFactory createRequestFactory(final HttpTransport transport) {

    return transport.createRequestFactory(new HttpRequestInitializer() {
    public void initialize(HttpRequest request) {
    GoogleHeaders headers = new GoogleHeaders();
    headers.setApplicationName("Google-Places-DemoApp");
    request.setHeaders(headers);
    JsonHttpParser parser = new JsonHttpParser();
    parser.jsonFactory = new JacksonFactory();
    request.addParser(parser);
    }
    });
    }

which simply does open an http connection to execute the search url

the problem is that at parser.jsonFactory = new JacksonFactory(); eclipse tell me that The field JsonHttpParser.jsonFactory is not visible. how can i solve this issue knowing that i have imported all necessary external jars.

Thank you

Upvotes: 1

Views: 785

Answers (2)

Lucas Tierney
Lucas Tierney

Reputation: 2563

It appears that Class JsonHttpParser and Method HttpRequest were both deprecated in version 1.11. See The Deprecated list for more information.

So instead of:

            JsonHttpParser parser = new JsonHttpParser();
            parser.jsonFactory = new JacksonFactory();
            request.addParser(parser);

Try:

            JsonObjectParser parser = new JsonObjectParser(new JacksonFactory());
            request.setParser(parser);

And use import:

import com.google.api.client.json.JsonObjectParser;

Note: Not tested.

Upvotes: 0

curlyreggie
curlyreggie

Reputation: 1530

I experienced the same problem before.

This is because the jsonFactory and headers variables are depracated since 1.6. If you are using Google APIs before 1.6 version, it should work properly.

Check this for more info:

  1. http://www.jarvana.com/jarvana/view/com/google/http-client/google-http-client/1.5.0-beta/google-http-client-1.5.0-beta-javadoc.jar!/com/google/api/client/http/json/JsonHttpParser.html#jsonFactory

  2. http://javadoc.google-http-java-client.googlecode.com/hg/1.5.0-beta/com/google/api/client/http/HttpRequest.html

You need to devise alternate methods to be used.

Use the below re-framed code:

GoogleHeaders headers = new GoogleHeaders();
headers.setApplicationName("Google-Places-DemoApp");
request.setHeaders(headers);

request.addParser(new JsonHttpParser(new JacksonFactory()));

Note: Not tested!

Upvotes: 1

Related Questions