Object Serialization to JSON (using Gson). How to set field names in UpperCamelCase?

Taken from the docs: Gson supports some pre-defined field naming policies to convert the standard Java field names (i.e. camel cased names starting with lower case — “sampleFieldNameInJava”) to a Json field name (i.e. sample_field_name_in_java or SampleFieldNameInJava). See the FieldNamingPolicy class for information on the pre-defined naming policies. It also has an annotation based strategy … Read more

What’s the most space-efficient way to compress serialized Python data?

I’ve done some test using a Pickled object, lzma gave the best compression. But your results can vary based on your data, I’d recommend testing them with some sample data of your own. Mode LastWriteTime Length Name —- ————- —— —- -a—- 9/17/2019 10:05 PM 23869925 no_compression.pickle -a—- 9/17/2019 10:06 PM 6050027 gzip_test.gz -a—- 9/17/2019 … Read more

django REST framework – limited queryset for nested ModelSerializer?

In your View Set you may specify the queryset like follows: from rest_framework import serializers, viewsets class MyModelSerializer(serializers.ModelSerializer): class Meta: model = MyModel class MyModelViewSet(viewsets.ModelViewSet): queryset = MyModel.objects.all()[:500] serializer_class = MyModelSerializer I think what you are looking for is the SerializerMethodField. So your code would look as follows: class ContainerSerializer(serializers.ModelSerializer): items = SerializerMethodField(‘get_items’) class Meta: … Read more

Deserialize millisecond timestamp to java.time.Instant

Solution was to add .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false) to the ObjectMapper. Complete ObjectMapper looks like: ObjectMapper om = new ObjectMapper() .registerModule(new JavaTimeModule()) .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false) .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false) .setSerializationInclusion(Include.NON_NULL);

Make a custom .NET Exception serializable

Base implementation, without custom properties SerializableExceptionWithoutCustomProperties.cs: namespace SerializableExceptions { using System; using System.Runtime.Serialization; [Serializable] // Important: This attribute is NOT inherited from Exception, and MUST be specified // otherwise serialization will fail with a SerializationException stating that // “Type X in Assembly Y is not marked as serializable.” public class SerializableExceptionWithoutCustomProperties : Exception { public … Read more

Use class name as root key for JSON Jackson serialization

By adding the jackson annotation @JsonTypeInfo in class level you can have the expected output. i just added no-changes in your class. package com.test.jackson; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.SerializationConfig; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo.As; import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; @JsonTypeInfo(include=As.WRAPPER_OBJECT, use=Id.NAME) public class MyPojo { // Remain same as you have } output: { “MyPojo”: { “id”: 4 } }

Serializing Lists of Classes to XML

Just to check, have you marked Bar as [Serializable]? Also, you need a parameter-less ctor on Bar, to deserialize Hmm, I used: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Foo f = new Foo(); f.BarList = new List<Bar>(); f.BarList.Add(new Bar { Property1 = … Read more