Husqvik / GraphQlClientGenerator

GraphQL C# client generator
MIT License
209 stars 48 forks source link

Need example of how to deserialize into these generated classes #158

Open KlomDark opened 2 months ago

KlomDark commented 2 months ago

Hi, trying very hard to figure out how to actually use these generated classes. I don't see anything about deserializing into them. Can I get an example please? I just end up with the class with all fields null.

Is there a special trick built into these classes?

I am trying the old school way like this:

GeneratedClassName response = null;
object json = JsonConvert.DeserializeObject(responseData);
if (json is JObject jObject)
{
  response = jObject.ToObject<GeneratedClassName>();
}

Any assistance greatly appreciated!

Husqvik commented 2 months ago
JsonConvert.DeserializeObject<GeneratedClassName>(responseData)

should normally work. I see you use default serializer settings. If the field name doesn't perfectly match property name it will not be deserialized.

Provide the actual json and the GeneratedClassName definition se we can see what's the problem.