Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2010-2011. Axon Framework
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.axonframework.serializer;
Interface describing a serialization mechanism. Implementations can serialize objects of given type T to an output stream and read the object back in from an input stream.

Parameters:
<T> The base type the serializer handles.
Author(s):
Allard Buijze
Since:
1.2
public interface Serializer<T> {

    
Serializes the given object to the given outputStream. This method does not close the outputStream after writing the object.

Parameters:
object The object to serialize
outputStream The outputStream to write the serialized data to
Throws:
java.io.IOException when an error occurs while writing to the stream
    void serialize(T objectOutputStream outputStreamthrows IOException;

    
Serialize the given object into a byte[].

Parameters:
object The object to serialize
Returns:
the byte array representing the serialized object.
    byte[] serialize(T object);

    
Deserializes the first object read from the given inputStream. The inputStream is not closed after reading. The resulting object instance is cast to the expected type.

Implementations are encouraged to only read the data needed for deserialization of the first encountered instance.

Parameters:
inputStream the stream providing the serialized data
Returns:
the serialized object, cast to the expected type
Throws:
java.io.IOException when an error occurs while reading from the stream
java.lang.ClassCastException if the first object in the stream is not an instance of <T>.
    T deserialize(InputStream inputStreamthrows IOException;

    
Deserializes the first object read from the given bytes. The bytes are not consumed from the array or modified in any way. The resulting object instance is cast to the expected type.

Parameters:
bytes the bytes providing the serialized data
Returns:
the serialized object, cast to the expected type
Throws:
java.lang.ClassCastException if the first object in the stream is not an instance of <T>.
    T deserialize(byte[] bytes);
New to GrepCode? Check out our FAQ X