0

I am trying to use Graph Java sdk to search DriveItem similar to sample given here.(https://learn.microsoft.com/zh-tw/graph/api/search-query?view=graph-rest-beta&tabs=java). But gets error as "com.microsoft.graph.models.SearchHit declares multiple JSON fields named _id". Seen similar issue reported at class A declares multiple JSON fields. But here the classes are in graph sdk library. Detailed exception as below

at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.Gson.fromJson(Gson.java:931) at com.google.gson.Gson.fromJson(Gson.java:1003) at com.google.gson.Gson.fromJson(Gson.java:975) at com.microsoft.graph.serializer.DefaultSerializer.deserializeObject(DefaultSerializer.java:101)

Any suggestions?

Renil Joy
  • 123
  • 5
  • You should not serialize/deserialize classes you don't define: define your classes (see the Data Transfer Object pattern) that can handle would not contain fields violating the Gson mechanics, and convert such objects to that API classes if possible. Or use a custom deserializer. Or try using another library that does not work with fields by default (it's the default for Gson). – terrorrussia-keeps-killing Aug 17 '21 at 08:34
  • Thanks for the response @fluffy. I used plain REST api call instead of Java SDK to proceed. This way I can control the serialize/deserialize of response. – Renil Joy Sep 15 '21 at 01:54

0 Answers0