Class ScalaMapSerde<K,V>
- Type Parameters:
K- The key typeV- The value type
- All Implemented Interfaces:
io.micronaut.serde.Serializer<scala.collection.Map<K,V>>, io.micronaut.serde.util.CustomizableSerializer<scala.collection.Map<K, V>>
Map, which is a JSON object rather than a list of pairs.
A Scala map is an iterable of Tuple2, so the serializer for the collections would
take it as one and write an array of tuples -- and then fail, because a tuple has no
introspection either. It needs its own handling for the same reason java.util.Map does:
the keys become the field names.
Reading a map back is ScalaCollectionDeserializer's job, for the reason given
there.
Declared over any key type, as java.util.Map's own serializer is: a serializer is
matched by the type arguments it declares, so one written for Map[String, V] did not
answer for a member declared Map[Int, V], and that member fell back to being
introspected as a bean. A JSON key is a string whatever the map's key is; the key is written
as its string form, and the deserializer converts it back to the declared key type.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.micronaut.serde.Serializer
io.micronaut.serde.Serializer.EncoderContext -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateSpecific(io.micronaut.serde.Serializer.EncoderContext context, io.micronaut.core.type.Argument<? extends scala.collection.Map<K, V>> type) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.serde.util.CustomizableSerializer
isAbsent, isEmpty, serializeMethods inherited from interface io.micronaut.serde.Serializer
isDefault
-
Constructor Details
-
ScalaMapSerde
public ScalaMapSerde()
-
-
Method Details
-
createSpecific
public io.micronaut.serde.Serializer<scala.collection.Map<K,V>> createSpecific(io.micronaut.serde.Serializer.EncoderContext context, io.micronaut.core.type.Argument<? extends scala.collection.Map<K, V>> type) throws io.micronaut.serde.exceptions.SerdeException- Specified by:
createSpecificin interfaceio.micronaut.serde.Serializer<K>- Throws:
io.micronaut.serde.exceptions.SerdeException
-