Ściąganie danych z api - biblioteka

0

Witam,
Dane: https://api.aminer.org/api/search/pub/advanced?name=Albert%20Einstein&size=3
Potrzebuje jakieś biblioteki dla Javy przy pomocy, której będę mógł pobrać te dane i w jakiś prostu sposób stworzyć listę obiektów, tak aby każdy obiekt zawierał następujące informację:
-tytuł,
-autor,
-rok wydania,
-isbn itp.
Może ktoś podpowiedzieć czego użyć?

0
package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.List;

@SpringBootApplication
public class AminerAApplication {

	public static void main(String[] args) {
		SpringApplication.run(AminerAApplication.class, args);
		RestTemplate restTemplate = new RestTemplate();
		String URL = "https://api.aminer.org/api/search/pub/advanced?name=Zbigniew%20Suraj&size=2";

		ResponseEntity<Article[]> responseEntity = restTemplate.getForEntity(URL, Article[].class);
		Article[] articles = responseEntity.getBody();
		MediaType contentType = responseEntity.getHeaders().getContentType();
		HttpStatus statusCode = responseEntity.getStatusCode();

		for(int i=0; i< articles.length; i++){
			System.out.println(articles[i].getTitle());
		}
	}
}

package com.example;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * Created by Marcin on 11.08.2016.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class Article {
    private String title;

    public Article() {
    }

    public Article(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}

Exception in thread "main" org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class [Lcom.example.Article;] and content type [text/plain;charset=utf-8]
	at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:109)
	at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:884)
	at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:868)
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:622)
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:580)
	at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:312)

W pom.xml mam to, ale dalej nie może skonwertować.

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>
0

No ale przecież ten json zwracany z tej strony nijak sie ma do obiektu na który mapujesz o_O On się ma według ciebie domyślić że chcesz zmapować jakieś tam wewnętrzne pola tego jsona? Bo ja w tym responsie widze zupełnie co innego niż listę obiektów article z polem title :D

{
  "topics": [],
  "result": [
    {
      "num_viewed": 0,
      "versions": [
        {
          "id": "53e2509120f7fff67751c2a7",
          "src": "msra",
          "sid": "2069333"
        },
        {
          "id": "56d8e28edabfae2eee1bfce2",
          "src": "mag",
          "sid": "75D60E7D"
        }
      ],
      "urls": [],
      "pdf": "",
      "hash_zh": "",
      "highlight": {
        "abstract": ""
      },
      "score": 19908.46484375,
      "author_ids": [
        "53f5b414dabfae472ef80501",
        "",
        ""
      ],
      "abstract": "",
      "pages": {
        "s": "",
        "e": ""
      },
      "num_citation": 4802,
      "year": 1926,
      "keywords_zh": [],
      "hash": "iottotbm",
      "id": "53e9b0bcb7602d9703b2d88a",
      "authors": [
        {
          "aff": {
            "desc": "",
            "id": ""
          },
          "name": "albert einstein",
          "num_viewed": 0,
          "avatar": "",
          "indices": {},
          "is_following": false,
          "revised": {
            "cname": "",
            "mid": "",
            "mtime": "1970-01-01 00:00:00",
            "cid": "",
            "mname": "",
            "ctime": "1970-01-01 00:00:00"
          },
          "locks": {},
          "pos": [],
          "hidden": false,
          "award": [],
          "bind": false,
          "contact": {
            "has_email_cr": false,
            "work": "",
            "bio": "",
            "edu": "",
            "fax": "",
            "homepage": "",
            "address": "",
            "has_email": false,
            "phone": ""
          },
          "work": [],
          "links": [],
          "edu": [],
          "id": "",
          "intr": [],
          "num_followed": 0,
          "honor": []
        },
        {
          "aff": {
            "desc": "",
            "id": ""
          },
          "name": "r furth",
          "num_viewed": 0,
          "avatar": "",
          "indices": {},
          "is_following": false,
          "revised": {
            "cname": "",
            "mid": "",
            "mtime": "1970-01-01 00:00:00",
            "cid": "",
            "mname": "",
            "ctime": "1970-01-01 00:00:00"
          },
          "locks": {},
          "pos": [],
          "hidden": false,
          "award": [],
          "bind": false,
          "contact": {
            "has_email_cr": false,
            "work": "",
            "bio": "",
            "edu": "",
            "fax": "",
            "homepage": "",
            "address": "",
            "has_email": false,
            "phone": ""
          },
          "work": [],
          "links": [],
          "edu": [],
          "id": "",
          "intr": [],
          "num_followed": 0,
          "honor": []
        },
        {
          "aff": {
            "desc": "",
            "id": ""
          },
          "name": "a d cowper",
          "num_viewed": 0,
          "avatar": "",
          "indices": {},
          "is_following": false,
          "revised": {
            "cname": "",
            "mid": "",
            "mtime": "1970-01-01 00:00:00",
            "cid": "",
            "mname": "",
            "ctime": "1970-01-01 00:00:00"
          },
          "locks": {},
          "pos": [],
          "hidden": false,
          "award": [],
          "bind": false,
          "contact": {
            "has_email_cr": false,
            "work": "",
            "bio": "",
            "edu": "",
            "fax": "",
            "homepage": "",
            "address": "",
            "has_email": false,
            "phone": ""
          },
          "work": [],
          "links": [],
          "edu": [],
          "id": "",
          "intr": [],
          "num_followed": 0,
          "honor": []
        }
      ],
      "abstract_zh": "",
      "isbn": "",
      "keywords": [],
      "title": "Investigations on the Theory of the Brownian Movement",
      "lang": "en",
      "doi": "",
      "num_starred": 0,
      "title_zh": "",
      "venue": {
        "series": 0,
        "name": "American Mathematical Monthly",
        "indices": {},
        "mid": "56992020b0b7fae0fc504b21",
        "info": {
          "name": "American Mathematical Monthly",
          "vtype": 1
        },
        "issue": "",
        "id": "56992020b0b7fae0fc504b21",
        "type": 1,
        "volume": ""
      },
      "issn": ""
    },
    {
      "num_viewed": 0,
      "versions": [
        {
          "id": "53e2532b20f7fff6775c0364",
          "src": "msra",
          "sid": "3671065"
        },
        {
          "id": "56d8e841dabfae2eee3f4fcc",
          "src": "mag",
          "sid": "787EA186"
        }
      ],
      "urls": [],
      "pdf": "",
      "hash_zh": "",
      "highlight": {
        "abstract": ""
      },
      "score": 14933.6689453125,
      "author_ids": [
        "53f5b414dabfae472ef80501"
      ],
      "abstract": "",
      "pages": {
        "s": "",
        "e": ""
      },
      "num_citation": 2212,
      "year": 1920,
      "keywords_zh": [],
      "hash": "rtsagt",
      "id": "53e99a14b7602d9702267381",
      "authors": [
        {
          "aff": {
            "id": ""
          },
          "name": "Albert Einstein",
          "num_viewed": 0,
          "avatar": "",
          "indices": {},
          "is_following": false,
          "revised": {
            "cname": "",
            "mid": "",
            "mtime": "1970-01-01 00:00:00",
            "cid": "",
            "mname": "",
            "ctime": "1970-01-01 00:00:00"
          },
          "locks": {},
          "pos": [],
          "hidden": false,
          "award": [],
          "bind": false,
          "contact": {
            "has_email_cr": false,
            "work": "",
            "bio": "",
            "edu": "",
            "fax": "",
            "homepage": "",
            "address": "",
            "has_email": false,
            "phone": ""
          },
          "work": [],
          "links": [],
          "edu": [],
          "id": "",
          "intr": [],
          "num_followed": 0,
          "honor": []
        }
      ],
      "abstract_zh": "",
      "isbn": "",
      "keywords": [],
      "title": "Relativity: The Special and General Theory",
      "lang": "en",
      "doi": "",
      "num_starred": 0,
      "title_zh": "",
      "venue": {
        "series": 0,
        "name": "The Philosophical Review",
        "indices": {},
        "mid": "55f96228c35f4fb0d21cf02f",
        "info": {
          "name": "The Philosophical Review",
          "vtype": 1
        },
        "issue": "",
        "id": "55f96228c35f4fb0d21cf02f",
        "type": 1,
        "volume": ""
      },
      "issn": ""
    },
    {
      "num_viewed": 0,
      "versions": [
        {
          "id": "53e2522d20f7fff6775809c5",
          "src": "msra",
          "sid": "2959131"
        },
        {
          "id": "56d8a98bdabfae2eeea81027",
          "src": "mag",
          "sid": "85BF8000"
        }
      ],
      "urls": [
        "http://dx.doi.org/10.1002/andp.19163540702"
      ],
      "pdf": "",
      "hash_zh": "",
      "highlight": {
        "abstract": ""
      },
      "score": 14545.6083984375,
      "author_ids": [
        "53f5b414dabfae472ef80501",
        ""
      ],
      "abstract": "",
      "pages": {
        "s": "769",
        "e": "822"
      },
      "num_citation": 2721,
      "year": 1916,
      "keywords_zh": [],
      "hash": "dgdar",
      "id": "53e9ab82b7602d970352ba36",
      "authors": [
        {
          "aff": {
            "desc": "",
            "id": ""
          },
          "name": "albert einstein",
          "num_viewed": 0,
          "avatar": "",
          "indices": {},
          "is_following": false,
          "revised": {
            "cname": "",
            "mid": "",
            "mtime": "1970-01-01 00:00:00",
            "cid": "",
            "mname": "",
            "ctime": "1970-01-01 00:00:00"
          },
          "locks": {},
          "pos": [],
          "hidden": false,
          "award": [],
          "bind": false,
          "contact": {
            "has_email_cr": false,
            "work": "",
            "bio": "",
            "edu": "",
            "fax": "",
            "homepage": "",
            "address": "",
            "has_email": false,
            "phone": ""
          },
          "work": [],
          "links": [],
          "edu": [],
          "id": "",
          "intr": [],
          "num_followed": 0,
          "honor": []
        },
        {
          "aff": {
            "desc": "",
            "id": ""
          },
          "name": "zugangsinformation",
          "num_viewed": 0,
          "avatar": "",
          "indices": {},
          "is_following": false,
          "revised": {
            "cname": "",
            "mid": "",
            "mtime": "1970-01-01 00:00:00",
            "cid": "",
            "mname": "",
            "ctime": "1970-01-01 00:00:00"
          },
          "locks": {},
          "pos": [],
          "hidden": false,
          "award": [],
          "bind": false,
          "contact": {
            "has_email_cr": false,
            "work": "",
            "bio": "",
            "edu": "",
            "fax": "",
            "homepage": "",
            "address": "",
            "has_email": false,
            "phone": ""
          },
          "work": [],
          "links": [],
          "edu": [],
          "id": "",
          "intr": [],
          "num_followed": 0,
          "honor": []
        }
      ],
      "abstract_zh": "",
      "isbn": "",
      "keywords": [
        "tensor"
      ],
      "title": "Die Grundlage der allgemeinen Relativitätstheorie",
      "lang": "en",
      "doi": "10.1002/andp.19163540702",
      "num_starred": 0,
      "title_zh": "",
      "venue": {
        "series": 0,
        "name": "Annalen Der Physik",
        "indices": {},
        "mid": "53e183e120f7dfbc07e8ca04",
        "info": {
          "name": "Annalen Der Physik",
          "vtype": 1
        },
        "issue": "7",
        "id": "53e183e120f7dfbc07e8ca04",
        "type": 1,
        "volume": "354"
      },
      "issn": ""
    }
  ],
  "total": 100,
  "status": true,
  "time": 6,
  "limit": 100
}

W ogóle nie widzę tu żadnej listy article z polem title ;]

0

Może napiszę co próbuję zrobić. Z witry aminer.org chce dostać listę publikacji danego autora. Tutaj jest niby api opisane: http://doc.aminer.org/en/latest/s/pub/advanced.html. Na przykład taki url: https://api.aminer.org/api/search/pub/advanced?name=Albert%20Einstein&size=3 można z tego wyciągnąć:
title":"Investigations on the Theory of the Brownian
title":"Relativity: The Special and General Theory
title":"Die Grundlage der allgemeinen Relativitätstheorie.
Na razie próbuje z samym tytułem, potem będę próbował z dodatkowymi polami tzn. isbn, rok wydania itp.

1

No ale tak to sie nie da. Nie ma tu jasnowidza który ogarnie jak ty chcesz tego jsona parsować. Musisz zrobić obiekt który odpowiada strukturze tego co dostajesz, ewentualnie pomijając jakieś pola. W twoim przypadku potrzebujesz obiektu który ma pole result które jest listą obiektów które mają pole title.

edit: poza tym jeszcze ta strona jest trochę zrypana bo zwraca text/plain zamiast application/json

1 użytkowników online, w tym zalogowanych: 0, gości: 1