Closed tonysneed closed 4 years ago
I have a Postgres connector that writes the following message:
i'm a bit confused. is this the contents of the message value? (i'm not that familiar with connect, so guessing) I don't think you can deserialize that as is with the .net json deserializer because it's an array at the top level.
and what is TKey
, TValue
?
I figured it out. Using the VS Code extension, Paste JSON as Code, I created the Value
and After
classes:
public partial class Value
{
[JsonProperty("before")]
public object Before { get; set; }
[JsonProperty("after")]
public After After { get; set; }
[JsonProperty("source")]
public Source Source { get; set; }
[JsonProperty("op")]
public string Op { get; set; }
[JsonProperty("ts_ms")]
public long TsMs { get; set; }
[JsonProperty("transaction")]
public object Transaction { get; set; }
}
public partial class After
{
[JsonProperty("person_id")]
public long PersonId { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("favorite_color")]
public string FavoriteColor { get; set; }
[JsonProperty("age")]
public long Age { get; set; }
}
Then I set the value deserializer to a JsonDeserializer<Value>
. The main envelope is already deserialized by the consumer, so all that's left is to properly deserialize the key and value.
TKey
and TValue
are just type arguments. I made the Run_Consumer
method in the sample generic.
Description
I have a Postgres connector that writes the following message:
I have the following class:
I build a consumer with deserializers set.
Consuming the message generates this error.
What is the best way to deserialize a JSON message from Kafka Connect?
How to reproduce
See the
json-converter
branch on my repo: https://github.com/event-streams-dotnet/connect-event-streams/blob/json-converter/Consumer/Program.csChecklist
Please provide the following information: