Example usage for java.io NotSerializableException NotSerializableException

List of usage examples for java.io NotSerializableException NotSerializableException

Introduction

In this page you can find the example usage for java.io NotSerializableException NotSerializableException.

Prototype

public NotSerializableException(String classname) 

Source Link

Document

Constructs a NotSerializableException object with message string.

Usage

From source file:org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.java

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    throw new NotSerializableException("An EntityManagerFactoryBean itself is not deserializable - "
            + "just a SerializedEntityManagerFactoryBeanReference is");
}

From source file:org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.java

protected Object writeReplace() throws ObjectStreamException {
    if (this.beanFactory != null && this.beanName != null) {
        return new SerializedEntityManagerFactoryBeanReference(this.beanFactory, this.beanName);
    } else {/*from w  w  w. j av a  2 s  .  c om*/
        throw new NotSerializableException("EntityManagerFactoryBean does not run within a BeanFactory");
    }
}

From source file:org.apache.empire.db.DBReader.java

private void writeObject(ObjectOutputStream stream) throws IOException {
    if (rset != null) {
        throw new NotSerializableException(DBReader.class.getName() + " (due to attached ResultSet)");
    }/*from w w w .  j a v  a2s. co m*/
}

From source file:com.novemberain.quartz.mongodb.MongoDBJobStore.java

protected void jobDataMapFromString(JobDataMap jobDataMap, String clob) throws IOException {

    try {/*from  w ww.j a v  a  2s.  c o m*/
        byte[] bytes = Base64.decodeBase64(clob);

        Map<String, ?> map = (Map<String, ?>) stringMapFromBytes(bytes);

        jobDataMap.putAll(map);
        jobDataMap.clearDirtyFlag();

    } catch (NotSerializableException e) {
        throw new NotSerializableException("Unable to serialize JobDataMap for insertion into "
                + "database because the value of property '"
                + getKeyOfNonSerializableStringMapEntry(jobDataMap.getWrappedMap()) + "' is not serializable: "
                + e.getMessage());
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.novemberain.quartz.mongodb.MongoDBJobStore.java

protected String jobDataToString(JobDataMap jobDataMap) throws IOException {

    try {/*from   ww w . j a v  a 2 s . co  m*/
        byte[] bytes = stringMapToBytes(jobDataMap.getWrappedMap());
        return Base64.encodeBase64String(bytes);
    } catch (NotSerializableException e) {
        throw new NotSerializableException("Unable to serialize JobDataMap for insertion into "
                + "database because the value of property '"
                + getKeyOfNonSerializableStringMapEntry(jobDataMap.getWrappedMap()).toString()
                + "' is not serializable: " + e.getMessage());
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

public static void basicWriteObject(Object o, DataOutput out, boolean ensurePdxCompatibility)
        throws IOException {
    checkOut(out);//w ww  .ja  v a  2 s.co  m

    final boolean isDebugEnabled_SERIALIZER = logger.isTraceEnabled(LogMarker.SERIALIZER);
    if (isDebugEnabled_SERIALIZER) {
        logger.trace(LogMarker.SERIALIZER, "basicWriteObject: {}", o);
    }

    // Handle special objects first
    if (o == null) {
        out.writeByte(NULL);

    } else if (o instanceof DataSerializableFixedID) {
        checkPdxCompatible(o, ensurePdxCompatibility);
        DataSerializableFixedID dsfid = (DataSerializableFixedID) o;
        writeDSFID(dsfid, out);
    } else if (autoSerialized(o, out)) {
        // all done
    } else if (o instanceof DataSerializable.Replaceable) {
        // do this first to fix bug 31609
        // do this before DataSerializable
        Object replacement = ((DataSerializable.Replaceable) o).replace();
        basicWriteObject(replacement, out, ensurePdxCompatibility);

    } else if (o instanceof PdxSerializable) {
        writePdx(out,
                GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed."), o,
                null);
    } else if (o instanceof DataSerializable) {
        if (isDebugEnabled_SERIALIZER) {
            logger.trace(LogMarker.SERIALIZER, "Writing DataSerializable: {}", o);
        }
        checkPdxCompatible(o, ensurePdxCompatibility);

        Class c = o.getClass();
        // Is "c" a user class registered with an Instantiator?
        int classId = InternalInstantiator.getClassId(c);
        if (classId != 0) {
            writeUserDataSerializableHeader(classId, out);
        } else {
            out.writeByte(DATA_SERIALIZABLE);
            DataSerializer.writeClass(c, out);
        }
        DataSerializable ds = (DataSerializable) o;
        invokeToData(ds, out);

    } else if (o instanceof Sendable) {
        if (!(o instanceof PdxInstance) || o instanceof PdxInstanceEnum) {
            checkPdxCompatible(o, ensurePdxCompatibility);
        }
        ((Sendable) o).sendTo(out);
    } else if (writeWellKnownObject(o, out, ensurePdxCompatibility)) {
        // Nothing more to do...
    } else {
        checkPdxCompatible(o, ensurePdxCompatibility);
        if (logger.isTraceEnabled(LogMarker.DUMP_SERIALIZED)) {
            logger.trace(LogMarker.DUMP_SERIALIZED, "DataSerializer Serializing an instance of {}",
                    o.getClass().getName());
        }

        /*
         * If the (internally known) ThreadLocal named "DataSerializer.DISALLOW_JAVA_SERIALIZATION" is
         * set, then an exception will be thrown if we try to do standard Java Serialization. This is
         * used to catch Java serialization early for the case where the data is being sent to a
         * non-Java client
         */
        if (disallowJavaSerialization() && o instanceof Serializable) {
            throw new NotSerializableException(
                    LocalizedStrings.DataSerializer_0_IS_NOT_DATASERIALIZABLE_AND_JAVA_SERIALIZATION_IS_DISALLOWED
                            .toLocalizedString(o.getClass().getName()));
        }

        writeSerializableObject(o, out);
    }
}

From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java

/**
 * <p>/*from  w  w  w .  j  av a  2s .  co  m*/
 * Remove the transient data from and then create a serialized <code>java.util.ByteArrayOutputStream</code>
 * version of a <code>{@link org.quartz.JobDataMap}</code>.
 * </p>
 * 
 * @param data
 *          the JobDataMap to serialize
 * @return the serialized ByteArrayOutputStream
 * @throws IOException
 *           if serialization causes an error
 */
protected ByteArrayOutputStream serializeJobData(JobDataMap data) throws IOException {
    if (canUseProperties()) {
        return serializeProperties(data);
    }

    try {
        return serializeObject(data);
    } catch (NotSerializableException e) {
        throw new NotSerializableException("Unable to serialize JobDataMap for insertion into "
                + "database because the value of property '" + getKeyOfNonSerializableValue(data)
                + "' is not serializable: " + e.getMessage());
    }
}

From source file:org.apache.openjpa.kernel.StateManagerImpl.java

/**
 * Write <code>pc</code> to <code>oos</code>, handling internal-form
 * serialization. <code>pc</code> must be of the same type that this
 * state manager manages./*from   w w  w .  j  av a 2 s.c o m*/
 *
 * @since 1.1.0
 */
void writePC(ObjectOutputStream oos, PersistenceCapable pc) throws IOException {
    if (!Serializable.class.isAssignableFrom(_meta.getDescribedType()))
        throw new NotSerializableException(_meta.getDescribedType().getName());

    oos.writeObject(pc);
}