I am trying to query a database and then convert the resultset obtained into json using the google gson library.While trying todo so, i am getting the error:
class com.mysql.jdbc.JDBC4Connection declares multiple JSON fields named connectionLifecycleInterceptors
I have tried to look for the connectionLifecycleInterceptors variable to change the name however i cant.Other questions in this context are not refering only to superclasses and subclass,while the error i am getting,i suppose comes from the database resultset.
public String convertToGson(ResultSet results) throws Exception
{ //code to convert resultset to gson
Gson gson = new Gson();
String gsonstring = gson.toJson(results);///it indicates the error is here
return gsonstring;
}
here is the error: java.lang.IllegalArgumentException: class com.mysql.jdbc.JDBC4Connection declares multiple JSON fields named connectionLifecycleInterceptors at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:172) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:56) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245) at com.google.gson.Gson.toJson(Gson.java:704) at com.google.gson.Gson.toJson(Gson.java:683) at com.google.gson.Gson.toJson(Gson.java:638) at com.google.gson.Gson.toJson(Gson.java:618) at sample.QueryCentre.convertToGson(QueryCentre.java:91) at sample.QueryCentre.showavailablerooms(QueryCentre.java:72) at sample.ServerSide.main(ServerSide.java:51)
1条答案
按热度按时间yhqotfr81#
ResultSet
不是常规的POJO
,您需要对其进行迭代并手动创建POJO
或Map
示例。在此转换之后,您可以将这些示例的列表传递给序列化进程。伪代码:
有用的方法:
另请参阅: