* @return A string representing the encoded form of the object; this is a javascript/json expression.
* @throws SerializationException
* If there is a problem during serialization
*/
public static String serializeObject(Object object, Class<?> clazz, boolean inScriptTag) throws SerializationException {
ServerSerializationStreamWriter stream = new ServerSerializationStreamWriter(new SerializationPolicy() {
@Override
public void validateSerialize(Class<?> clazz) throws SerializationException {
}
@Override
public void validateDeserialize(Class<?> clazz) throws SerializationException {
throw new SerializationException("Should only be used for serialization!");
}
@Override
public boolean shouldSerializeFields(Class<?> clazz) {
return clazz.getSuperclass() != null; // We'll allow anything but java.lang.Object, I guess
}
@Override
public boolean shouldDeserializeFields(Class<?> clazz) {
return false;
}
});
stream.prepareToWrite();
stream.serializeValue(object, clazz);
return stream.toString();
}