简体   繁体   中英

Serialize Tweetinvi using JsonConvert.SerializeObject

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 i n 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

Try following code:

private void SendToKinesis(ITweet tweet)
{


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

   //Send to Kinesis

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM