Spring Integration

org.springframework.integration.ip.tcp.serializer
Class MapJsonSerializer

java.lang.Object
  extended by org.springframework.integration.ip.tcp.serializer.MapJsonSerializer
All Implemented Interfaces:
org.springframework.core.serializer.Deserializer<java.util.Map<?,?>>, org.springframework.core.serializer.Serializer<java.util.Map<?,?>>

public class MapJsonSerializer
extends java.lang.Object
implements org.springframework.core.serializer.Serializer<java.util.Map<?,?>>, org.springframework.core.serializer.Deserializer<java.util.Map<?,?>>

Serializes a Map as JSON. Deserializes JSON to a Map. The default JacksonJsonObjectMapperProvider.newInstance() can be overridden using setJsonObjectMapper(JsonObjectMapper).

The JSON deserializer can't delimit multiple JSON objects. Therefore another (de)serializer is used to apply structure to the stream. By default, this is a simple ByteArrayLfSerializer, which inserts/expects LF (0x0a) between messages.

Since:
3.0
Author:
Gary Russell, Artem Bilan

Constructor Summary
MapJsonSerializer()
           
 
Method Summary
 java.util.Map<?,?> deserialize(java.io.InputStream inputStream)
           
 void serialize(java.util.Map<?,?> object, java.io.OutputStream outputStream)
           
 void setJsonObjectMapper(JsonObjectMapper<?> jsonObjectMapper)
          An JsonObjectMapper to be used for the conversion to/from JSON.
 void setPacketDeserializer(org.springframework.core.serializer.Deserializer<byte[]> packetDeserializer)
          A Deserializer that will construct the full JSON content from the stream which is then passed to the JsonObjectMapper.
 void setPacketSerializer(org.springframework.core.serializer.Serializer<byte[]> packetSerializer)
          A Serializer that will delimit the full JSON content in the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapJsonSerializer

public MapJsonSerializer()
Method Detail

setJsonObjectMapper

public void setJsonObjectMapper(JsonObjectMapper<?> jsonObjectMapper)
An JsonObjectMapper to be used for the conversion to/from JSON. Use this if you wish to set additional JsonObjectMapper implementation features.

Parameters:
jsonObjectMapper - the jsonObjectMapper.

setPacketDeserializer

public void setPacketDeserializer(org.springframework.core.serializer.Deserializer<byte[]> packetDeserializer)
A Deserializer that will construct the full JSON content from the stream which is then passed to the JsonObjectMapper. Default is ByteArrayLfSerializer.

Parameters:
packetDeserializer - the packetDeserializer

setPacketSerializer

public void setPacketSerializer(org.springframework.core.serializer.Serializer<byte[]> packetSerializer)
A Serializer that will delimit the full JSON content in the stream. Default is ByteArrayLfSerializer.

Parameters:
packetSerializer - the packetSerializer

deserialize

public java.util.Map<?,?> deserialize(java.io.InputStream inputStream)
                               throws java.io.IOException
Specified by:
deserialize in interface org.springframework.core.serializer.Deserializer<java.util.Map<?,?>>
Throws:
java.io.IOException

serialize

public void serialize(java.util.Map<?,?> object,
                      java.io.OutputStream outputStream)
               throws java.io.IOException
Specified by:
serialize in interface org.springframework.core.serializer.Serializer<java.util.Map<?,?>>
Throws:
java.io.IOException

Spring Integration