-
Notifications
You must be signed in to change notification settings - Fork 60
Collections (v1.x)
Recall that our serializer for “A” contained a List of "B"s, rather than a single “B”. In our object model, we will very likely have places where we need to make use of Lists, Sets, and Maps. NFTypeSerializers can be used to describe these elements.
Suppose we have a class D, which contains a List, a Set, and a Map:
We will need to define serializers for each of our collections. However, Zeno provides convenient classes for doing so. Let’s take a look at the serializer for D:
Notice the requiredSubSerializers method in the serializer above. We used three classes from the package com.netflix.zeno.serializer.common. These classes allow us to define serializers for collections without creating new classes. In the constructors of the collection serializers, we pass a type name and a serializer for the individual elements. In the constructors for the map serializer, we pass a type name, and a serializer for the key type, and a serializer for the value type.
If we have collections containing the same type of objects used across multiple serializers, we can pass the same type name to the constructors of the collection serializers instantiated in the requiredSubSerializers methods. This will allow deduplication across the fields in both objects for identical lists.
You may have noticed that the above example includes a reference to a serializer called IntegerSerializer. This is one of a few serializers which can be used to reference primitive types. Continue to the next page, Common Serializers (v1.x), to learn more.