blob: 1efd164e1c32ccf62e215be15828828f71e372d5 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.directmemory.lightning;
import java.io.IOException;
import org.apache.directmemory.lightning.base.AbstractSerializerDefinition;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
/**
* Implementations of the Marshaller interface are used to serialize / deserialize object instances. Normally marshaller
* implementations are autogenerated by Lightning using the descriptions given {@link AbstractSerializerDefinition}s.
*/
public interface Marshaller
{
/**
* Checks if a given type can be (de-) serialized with this marshaller implementation.
*
* @param type The type to check for being serializable by this marshaller
* @return true if the type can be (de-) serialized by this marshaller otherwise it returns false
*/
boolean acceptType( Class<?> type );
/**
* Marshalls (serializes) an given object instance of a supported type, previously checked by acceptType.
*
* @param value Object instance to serialize
* @param propertyDescriptor The {@link PropertyDescriptor} of this object
* @param target The {@link Target} implementation to write to
* @param serializationContext The {@link SerializationContext} used to serialize this object graph
* @throws IOException Throws {@link IOException} if any exception occurs while writing to the {@link Target}
*/
void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException;
/**
* Unmarshalls (deserializes) an object from the given {@link Source}.
*
* @param propertyDescriptor The {@link PropertyDescriptor} of this object
* @param source The {@link Source} implementation to read from
* @param serializationContext The {@link SerializationContext} used to deserialize this object graph
* @return An object read from the given {@link Source}
* @throws IOException Throws {@link IOException} if any exception occurs while reading from the {@link Source}
*/
<V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source, SerializationContext serializationContext )
throws IOException;
}