/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { SomeObjectType result; String urlString; // works Type returnType = new TypeToken<SomeObjectType>() { }.getType(); result = (SomeObjectType) Utils.urlToGson(urlString,returnType); // fails, unable to cast someInternalListType to SomeObjectType result = Utils.urlToGson(urlString); } CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(urlString); CloseableHttpResponse response1 = httpclient.execute(httpGet); Type returnType = new TypeToken<T>() { }.getType(); HttpEntity entity1 = response1.getEntity(); Gson gson = new Gson(); // Or use new GsonBuilder().create(); return (T)gson.fromJson(EntityUtils.toString(entity1), returnType); // deserializes } CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(urlString); CloseableHttpResponse response1 = httpclient.execute(httpGet); HttpEntity entity1 = response1.getEntity(); Gson gson = new Gson(); // Or use new GsonBuilder().create(); return gson.fromJson(EntityUtils.toString(entity1), returnType); // deserializes } }
Standard input is empty
Main.java:7: error: package com.google.gson does not exist
import com.google.gson.Gson;
^
Main.java:8: error: package com.google.gson.reflect does not exist
import com.google.gson.reflect.TypeToken;
^
Main.java:39: error: cannot find symbol
public static Object urlToGson(String urlString, Type returnType) {
^
symbol: class Type
location: class Ideone
Main.java:14: error: cannot find symbol
SomeObjectType result;
^
symbol: class SomeObjectType
location: class Ideone
Main.java:17: error: cannot find symbol
Type returnType = new TypeToken<SomeObjectType>() {
^
symbol: class Type
location: class Ideone
Main.java:17: error: cannot find symbol
Type returnType = new TypeToken<SomeObjectType>() {
^
symbol: class TypeToken
location: class Ideone
Main.java:17: error: cannot find symbol
Type returnType = new TypeToken<SomeObjectType>() {
^
symbol: class SomeObjectType
location: class Ideone
Main.java:19: error: cannot find symbol
result = (SomeObjectType) Utils.urlToGson(urlString,returnType);
^
symbol: class SomeObjectType
location: class Ideone
Main.java:19: error: cannot find symbol
result = (SomeObjectType) Utils.urlToGson(urlString,returnType);
^
symbol: variable Utils
location: class Ideone
Main.java:22: error: cannot find symbol
result = Utils.urlToGson(urlString);
^
symbol: variable Utils
location: class Ideone
Main.java:26: error: cannot find symbol
CloseableHttpClient httpclient = HttpClients.createDefault();
^
symbol: class CloseableHttpClient
location: class Ideone
Main.java:26: error: cannot find symbol
CloseableHttpClient httpclient = HttpClients.createDefault();
^
symbol: variable HttpClients
location: class Ideone
Main.java:27: error: cannot find symbol
HttpGet httpGet = new HttpGet(urlString);
^
symbol: class HttpGet
location: class Ideone
Main.java:27: error: cannot find symbol
HttpGet httpGet = new HttpGet(urlString);
^
symbol: class HttpGet
location: class Ideone
Main.java:28: error: cannot find symbol
CloseableHttpResponse response1 = httpclient.execute(httpGet);
^
symbol: class CloseableHttpResponse
location: class Ideone
Main.java:30: error: cannot find symbol
Type returnType = new TypeToken<T>() {
^
symbol: class Type
location: class Ideone
Main.java:30: error: cannot find symbol
Type returnType = new TypeToken<T>() {
^
symbol: class TypeToken
location: class Ideone
Main.java:33: error: cannot find symbol
HttpEntity entity1 = response1.getEntity();
^
symbol: class HttpEntity
location: class Ideone
Main.java:35: error: cannot find symbol
Gson gson = new Gson(); // Or use new GsonBuilder().create();
^
symbol: class Gson
location: class Ideone
Main.java:35: error: cannot find symbol
Gson gson = new Gson(); // Or use new GsonBuilder().create();
^
symbol: class Gson
location: class Ideone
Main.java:36: error: cannot find symbol
return (T)gson.fromJson(EntityUtils.toString(entity1), returnType); // deserializes
^
symbol: variable EntityUtils
location: class Ideone
Main.java:40: error: cannot find symbol
CloseableHttpClient httpclient = HttpClients.createDefault();
^
symbol: class CloseableHttpClient
location: class Ideone
Main.java:40: error: cannot find symbol
CloseableHttpClient httpclient = HttpClients.createDefault();
^
symbol: variable HttpClients
location: class Ideone
Main.java:41: error: cannot find symbol
HttpGet httpGet = new HttpGet(urlString);
^
symbol: class HttpGet
location: class Ideone
Main.java:41: error: cannot find symbol
HttpGet httpGet = new HttpGet(urlString);
^
symbol: class HttpGet
location: class Ideone
Main.java:42: error: cannot find symbol
CloseableHttpResponse response1 = httpclient.execute(httpGet);
^
symbol: class CloseableHttpResponse
location: class Ideone
Main.java:43: error: cannot find symbol
HttpEntity entity1 = response1.getEntity();
^
symbol: class HttpEntity
location: class Ideone
Main.java:45: error: cannot find symbol
Gson gson = new Gson(); // Or use new GsonBuilder().create();
^
symbol: class Gson
location: class Ideone
Main.java:45: error: cannot find symbol
Gson gson = new Gson(); // Or use new GsonBuilder().create();
^
symbol: class Gson
location: class Ideone
Main.java:46: error: cannot find symbol
return gson.fromJson(EntityUtils.toString(entity1), returnType); // deserializes
^
symbol: variable EntityUtils
location: class Ideone
30 errors
Standard output is empty