how to get newtonsoft to deserialize yes and no to boolean

public class MyBooleanConverter : JsonConverter { public override bool CanWrite { get { return false; } } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { throw new NotImplementedException(); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var value = reader.Value; if (value == null || String.IsNullOrWhiteSpace(value.ToString())) { return … Read more

Json.net serialization of custom collection implementing IEnumerable

As of Json.NET 6.0 Release 3 and later (I tested on 8.0.3), this works automatically as long as the custom class implementing IEnumerable<MyType> has a constructor that takes an IEnumerable<MyType> input argument. From the release notes: To all future creators of immutable .NET collections: If your collection of T has a constructor that takes IEnumerable … Read more

Jackson deserialize based on type

Annotations-only approach Alternatively to the custom deserializer approach, you can have the following for an annotations-only solution (similar to the one described in Spunc’s answer, but using type as an external property): public abstract class AbstractData { private Owner owner; private Metadata metadata; // Getters and setters } public static final class FooData extends AbstractData … Read more

WCF service The maximum array length quota (16384) has been exceeded

Actually, I’ve solved the problem by adding readerQuotas within textMessageEncoding section. Thanks for the help. <textMessageEncoding messageVersion=”Soap11″> <readerQuotas maxDepth=”32″ maxStringContentLength=”5242880″ maxArrayLength=”2147483646″ maxBytesPerRead=”4096″ maxNameTableCharCount=”5242880″/> </textMessageEncoding>

What difference between pickle and _pickle in python 3?

The pickle module already imports _pickle if available. It is the C-optimized version of the pickle module, and is used transparently. From the pickle.py source code: # Use the faster _pickle if possible try: from _pickle import * except ImportError: Pickler, Unpickler = _Pickler, _Unpickler and from the pickle module documentation: The pickle module has … Read more

context in nested serializers django rest framework

Ok i found a working solution. I replaced the ChildSerializer assignment in the Parent class with a SerializerMethodField which adds the context. This is then passed to the get_fields method in my CustomModelSerializer: class ChildSerializer(CustomModelSerializer): class Meta: fields = (‘c_name’, ) model = Child class ParentSerializer(CustomModelSerializer): child = serializers.SerializerMethodField(‘get_child_serializer’) class Meta: model = Parent fields … Read more

NewtonSoft.Json Serialize and Deserialize class with property of type IEnumerable

You don’t need to use JsonConverterAttribute, just keep your model clean and use CustomCreationConverter instead, the code is simpler: public class SampleConverter : CustomCreationConverter<ISample> { public override ISample Create(Type objectType) { return new Sample(); } } Then: var sz = JsonConvert.SerializeObject( sampleGroupInstance ); JsonConvert.DeserializeObject<SampleGroup>( sz, new SampleConverter()); Documentation: Deserialize with CustomCreationConverter

Unserialize in Java a serialized php object

There is serialized-php-parser, which is a Java implementation that can parse php-serialized objects. In general, if you have the choice, I wouldn’t recommend php-serialized as an exchange format, because it isn’t ascii-safe (It contains null-bytes). Go with a format like xml or json instead. If you need a bit of type-information, xmlrpc is a good … Read more