Answer the question
In order to leave comments, you need to log in
How to solve the problem with Gson?
That's when I create an instance of the gson class and shove my collection there, a buffer overflow pops up
try{
//конектимся
Document doc = Jsoup.connect("http://" + parserParam).get();
//добавляем в список из элементов все что лежит между тегами <html> </html>
List<Element> elements = doc.select("html");
//после вот этого кусочка
Gson gson = new GsonBuilder().create();
gson.toJson(elements);
/***Если стоит галка - текст
* выводим на клиента все что спарсилось в плэйн тексте
* иначе, выводим просто в хтмл
* */
if (toText != null){
out.print("<plaintext>" +elements + "</plaintext>");
}
else{
//System.out.println(jsonOut);
out.print(elements);
}
}
//перехватываем исключение если че
catch(Exception e){
e.printStackTrace();
out.print("ERROR, possible somthing wrong with your query");
}
java.lang.StackOverflowError
com.google.gson.internal.$Gson$Types.equals($Gson$Types.java:159)
com.google.gson.reflect.TypeToken.equals(TypeToken.java:284)
java.util.HashMap.getNode(HashMap.java:571)
java.util.HashMap.get(HashMap.java:556)
java.util.Collections$SynchronizedMap.get(Collections.java:2584)
com.google.gson.Gson.getAdapter(Gson.java:335)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:55)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:899)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:899)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:899)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
Answer the question
In order to leave comments, you need to log in
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class EntryPoint {
public static void main(final String args[]) {
final String fileName = "output.html";
final String url = "https://mail.ru/";
try (final BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) {
final Document doc = Jsoup.connect(url).get();
writer.write(doc.outerHtml());
} catch (final IOException e) {
// Error handling
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question