jadex.transformation.jsonserializer.processors.JsonReferenceProcessor Maven / Gradle / Ivy
package jadex.transformation.jsonserializer.processors;
import java.lang.reflect.Type;
import java.util.List;
import com.eclipsesource.json.JsonObject;
import jadex.common.transformation.IStringConverter;
import jadex.common.transformation.traverser.ITraverseProcessor;
import jadex.common.transformation.traverser.Traverser;
import jadex.common.transformation.traverser.Traverser.MODE;
import jadex.transformation.jsonserializer.JsonTraverser;
/**
*
*/
public class JsonReferenceProcessor implements ITraverseProcessor
{
/**
* Test if the processor is applicable.
* @param object The object.
* @param targetcl If not null, the traverser should make sure that the result object is compatible with the class loader,
* e.g. by cloning the object using the class loaded from the target class loader.
* @return True, if is applicable.
*/
public boolean isApplicable(Object object, Type type, ClassLoader targetcl, Object context)
{
return object instanceof JsonObject && ((JsonObject)object).get(JsonTraverser.REFERENCE_MARKER)!=null;
}
/**
* Process an object.
* @param object The object.
* @param targetcl If not null, the traverser should make sure that the result object is compatible with the class loader,
* e.g. by cloning the object using the class loaded from the target class loader.
* @return The processed object.
*/
public Object process(Object object, Type type, Traverser traverser, List conversionprocessors, List processors, IStringConverter converter, MODE mode, ClassLoader targetcl, Object context)
{
JsonObject obj = (JsonObject)object;
int num = obj.getInt(JsonTraverser.REFERENCE_MARKER, 0);
return ((JsonReadContext)context).getKnownObject(num);
// return traversed.get(Integer.valueOf(num));
}
}