Serialize Tweetinvi using JsonConvert.SerializeObject

1.3k views Asked by At

I am trying to get the following code to work, but a not implemented exception get thrown when I try to Serialize the object. It states "The method or operation is not implemented." I have tried implementing ITweet as a concrete class, but I can not go from the interface to concrete class.

private void SendToKinesis(ITweet tweet)
    {


        var dataAsJson = JsonConvert.SerializeObject(tweet);
        byte[] dataAsBytes = Encoding.UTF8.GetBytes(dataAsJson);

       //Send to Kinesis

    }

Complete Exception:

System.NotImplementedException: The method or operation is not implemented. at Tweetinvi.Logic.JsonConverters.JsonPropertyConverterRepository.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonConvert.SerializeObjectInternalA first chance exception of type 'System.NotImplementedException' occurred in TwitterIngestion.exe (Object value, Type type, JsonSerializer jsonSerializer) at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.SerializeObject(Object value) at TwitterIngestion.IngestionService.SendToKinesis(ITweet tweet) in c:\Users\sepehr500\Desktop\Work Stuff\TwitterIngestion\TwitterIngestion\IngestionTask.cs:line 104

1

There are 1 answers

1
AudioBubble On

Try following code:

private void SendToKinesis(ITweet tweet)
{


    var dataAsJson = JsonConvert.SerializeObject<ITweet>(tweet);
    byte[] dataAsBytes = Encoding.UTF8.GetBytes(dataAsJson);

   //Send to Kinesis

}