Java Code Examples for java.io.ObjectOutputStream

The following examples show how to use java.io.ObjectOutputStream. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dragonwell8_jdk   Source File: ObjArrays.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, Node[][] arrays, int nbatches)
    throws Exception
{
    int ncycles = arrays.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(arrays[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
 
Example 2
/**
 * Serializes a {@link ModelMBeanInfoSupport} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
throws IOException {
    if (compat) {
        // Serializes this instance in the old serial form
        //
        ObjectOutputStream.PutField fields = out.putFields();
        fields.put("modelMBeanDescriptor", modelMBeanDescriptor);
        fields.put("mmbAttributes", modelMBeanAttributes);
        fields.put("mmbConstructors", modelMBeanConstructors);
        fields.put("mmbNotifications", modelMBeanNotifications);
        fields.put("mmbOperations", modelMBeanOperations);
        fields.put("currClass", currClass);
        out.writeFields();
    } else {
        // Serializes this instance in the new serial form
        //
        out.defaultWriteObject();
    }
}
 
Example 3
Source Project: openjdk-8   Source File: NumericValueExp.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serializes a {@link NumericValueExp} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("doubleVal", doubleValue());
    fields.put("longVal", longValue());
    fields.put("valIsLong", isLong());
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 4
Source Project: frog   Source File: EggTool.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Frogs which have higher energy lay eggs
 * 
 * 利用Java串行机制存盘。 能量多(也就是吃的更多)的Frog下蛋并存盘, 以进行下一轮测试,能量少的Frog被淘汰,没有下蛋的资格。
 * 用能量的多少来简化生存竟争模拟,每次下蛋数量固定为EGG_QTY个
 */
public static void layEggs() {
	sortFrogsOrderByEnergyDesc();

	Frog first = Env.frogs.get(0);
	Frog last = Env.frogs.get(Env.frogs.size() - 1);

	try {
		Env.eggs.clear();
		for (int i = 0; i < Env.EGG_QTY; i++)
			Env.eggs.add(new Egg(Env.frogs.get(i)));
		FileOutputStream fo = new FileOutputStream(Application.CLASSPATH + "eggs.ser");
		ObjectOutputStream so = new ObjectOutputStream(fo);
		so.writeObject(Env.eggs);
		so.close();
		System.out.print("\r1st frog has " + first.organs.size() + " organs, energy=" + first.energy  );
		System.out.println(", Last frog has " + last.organs.size() + " organs,  energy=" + last.energy);
		System.out.println("Saved "+Env.eggs.size() +" eggs to file '" + Application.CLASSPATH + "eggs.ser'");
	} catch (IOException e) {
		System.out.println(e);
	}
}
 
Example 5
/**
 * Serializes a {@link ModelMBeanOperationInfo} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("operationDescriptor", operationDescriptor);
    fields.put("currClass", currClass);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 6
Source Project: Flink-CEPplus   Source File: MemoryCheckpointStorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskOwnedStateStream() throws Exception {
	final List<String> state = Arrays.asList("Flopsy", "Mopsy", "Cotton Tail", "Peter");

	final MemoryBackendCheckpointStorage storage = new MemoryBackendCheckpointStorage(
			new JobID(), null, null, DEFAULT_MAX_STATE_SIZE);

	StreamStateHandle stateHandle;

	try (CheckpointStateOutputStream stream = storage.createTaskOwnedStateStream()) {
		assertTrue(stream instanceof MemoryCheckpointOutputStream);

		new ObjectOutputStream(stream).writeObject(state);
		stateHandle = stream.closeAndGetHandle();
	}

	try (ObjectInputStream in = new ObjectInputStream(stateHandle.openInputStream())) {
		assertEquals(state, in.readObject());
	}
}
 
Example 7
Source Project: netbeans   Source File: EventBufferDumpedCommand.java    License: Apache License 2.0 6 votes vote down vote up
void writeObject(ObjectOutputStream out) throws IOException {
    out.writeInt(bufSize);
    out.writeBoolean(buffer != null);
    if (buffer != null) {
        Deflater compressor = new Deflater();
        // for small buffers, the compressed size can be somewhat larger than the original  
        byte[] compressedBytes = new byte[bufSize + 32]; 
        int compressedSize;
        
        compressor.setInput(buffer,startPos,bufSize);
        compressor.finish();
        compressedSize = compressor.deflate(compressedBytes);
        out.writeInt(compressedSize);
        out.write(compressedBytes,0,compressedSize);
    } else {
        out.writeUTF(eventBufferFileName);
    }
}
 
Example 8
Source Project: j2objc   Source File: DateFormatSymbolsTest.java    License: Apache License 2.0 6 votes vote down vote up
public void test_serialization() throws Exception {
    DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRANCE);
    String[][] zoneStrings = symbols.getZoneStrings();
    assertNotNull(zoneStrings);

    // serialize
    ByteArrayOutputStream byteOStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOStream = new ObjectOutputStream(byteOStream);
    objectOStream.writeObject(symbols);

    // and deserialize
    ObjectInputStream objectIStream = new ObjectInputStream(
            new ByteArrayInputStream(byteOStream.toByteArray()));
    DateFormatSymbols symbolsD = (DateFormatSymbols) objectIStream
            .readObject();

    String[][] zoneStringsD = symbolsD.getZoneStrings();
    assertNotNull(zoneStringsD);
    assertEquals(symbols, symbolsD);
}
 
Example 9
Source Project: dragonwell8_jdk   Source File: Permissions.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Default fields.
 */
/*
 * Writes the contents of the permsMap field out as a Hashtable for
 * serialization compatibility with earlier releases.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Don't call out.defaultWriteObject()

    // Copy perms into a Hashtable
    Hashtable<Permission, Permission> perms =
            new Hashtable<>(permsMap.size()*2);
    synchronized (this) {
        perms.putAll(permsMap);
    }

    // Write out serializable fields
    ObjectOutputStream.PutField pfields = out.putFields();
    pfields.put("perms", perms);
    out.writeFields();
}
 
Example 10
/**
 * Write and read class descriptors to/from a stream.
 * Arguments: <# cycles>
 */
public long run(String[] args) throws Exception {
    int ncycles = Integer.parseInt(args[0]);
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());
    ObjectStreamClass desc = ObjectStreamClass.lookup(Dummy50.class);

    doReps(oout, oin, sbuf, desc, 1);       // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, desc, ncycles);
    return System.currentTimeMillis() - start;
}
 
Example 11
Source Project: datawave   Source File: EdgeQueryLogic.java    License: Apache License 2.0 6 votes vote down vote up
protected String serializePrefilter() {
    
    String retVal = null;
    if (prefilterValues != null) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(prefilterValues);
            oos.close();
        } catch (IOException ex) {
            log.error("Some error encoding the prefilters...", ex);
        }
        retVal = new String(Base64.encodeBase64(baos.toByteArray()));
    }
    
    return retVal;
}
 
Example 12
Source Project: openjdk-8-source   Source File: FloatArrays.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, float[][] arrays, int nbatches)
    throws Exception
{
    int ncycles = arrays.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(arrays[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
 
Example 13
Source Project: ThriftBook   Source File: FileTrans.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) 
        throws IOException, TTransportException, ClassNotFoundException {
    Trade trade = new Trade();
    trade.symbol = "F";
    trade.price = 13.10;
    trade.size = 2500;

    TSimpleFileTransport trans_out = new TSimpleFileTransport("data",false,true);	
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(trade);
    trans_out.write(baos.toByteArray());				
    trans_out.close();				

    TSimpleFileTransport trans_in = new TSimpleFileTransport("data",true,false);
    byte[] buf = new byte[128];
    int iBytesRead = trans_in.read(buf, 0, buf.length);		
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);
    ObjectInputStream ois = new ObjectInputStream(bais);
    trade = (Trade) ois.readObject();

    System.out.println("Trade(" + iBytesRead + "): " + trade.symbol
            + " " + trade.size + " @ " + trade.price);
}
 
Example 14
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    StackedXYAreaRenderer r1 = new StackedXYAreaRenderer();
    r1.setShapePaint(Color.red);
    r1.setShapeStroke(new BasicStroke(1.23f));
    StackedXYAreaRenderer r2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(r1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        r2 = (StackedXYAreaRenderer) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(r1, r2);
}
 
Example 15
Source Project: astor   Source File: StrokeMapTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for serialization.
 */
public void testSerialization2() {
    StrokeMap m1 = new StrokeMap();
    m1.put("K1", new BasicStroke(1.1f));
    m1.put("K2", new BasicStroke(2.2f));
    StrokeMap m2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(m1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(
                buffer.toByteArray()));
        m2 = (StrokeMap) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(m1, m2);
}
 
Example 16
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    MeanAndStandardDeviation m1 = new MeanAndStandardDeviation(1.2, 3.4);
    MeanAndStandardDeviation m2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(m1);
        out.close();

        ObjectInput in = new ObjectInputStream(
            new ByteArrayInputStream(buffer.toByteArray())
        );
        m2 = (MeanAndStandardDeviation) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(m1, m2);

}
 
Example 17
Source Project: hottub   Source File: DocumentImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example 18
Source Project: openjdk-jdk8u   Source File: SmallObjTrees.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Run benchmark for given number of batches, with each batch containing the
 * given number of cycles.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, Node[] trees, int nbatches)
    throws Exception
{
    int ncycles = trees.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(trees[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
 
Example 19
Source Project: ratis   Source File: ArithmeticStateMachine.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public long takeSnapshot() {
  final Map<String, Double> copy;
  final TermIndex last;
  try(final AutoCloseableLock readLock = readLock()) {
    copy = new HashMap<>(variables);
    last = getLastAppliedTermIndex();
  }

  final File snapshotFile =  storage.getSnapshotFile(last.getTerm(), last.getIndex());
  LOG.info("Taking a snapshot to file {}", snapshotFile);

  try(final ObjectOutputStream out = new ObjectOutputStream(
      new BufferedOutputStream(new FileOutputStream(snapshotFile)))) {
    out.writeObject(copy);
  } catch(IOException ioe) {
    LOG.warn("Failed to write snapshot file \"" + snapshotFile
        + "\", last applied index=" + last);
  }

  return last.getIndex();
}
 
Example 20
Source Project: openjdk-8   Source File: Ints.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write and read int values to/from a stream.  The benchmark is run in
 * batches: each "batch" consists of a fixed number of read/write cycles,
 * and the stream is flushed (and underlying stream buffer cleared) in
 * between each batch.
 * Arguments: <# batches> <# cycles per batch>
 */
public long run(String[] args) throws Exception {
    int nbatches = Integer.parseInt(args[0]);
    int ncycles = Integer.parseInt(args[1]);
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());

    doReps(oout, oin, sbuf, 1, ncycles);    // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, nbatches, ncycles);
    return System.currentTimeMillis() - start;
}
 
Example 21
Source Project: jdk8u_jdk   Source File: ShortArrays.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write and read short arrays to/from a stream.  The benchmark is run in
 * batches, with each batch consisting of a fixed number of read/write
 * cycles.  The ObjectOutputStream is reset after each batch of cycles has
 * completed.
 * Arguments: <array size> <# batches> <# cycles per batch>
 */
public long run(String[] args) throws Exception {
    int size = Integer.parseInt(args[0]);
    int nbatches = Integer.parseInt(args[1]);
    int ncycles = Integer.parseInt(args[2]);
    short[][] arrays = new short[ncycles][size];
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());

    doReps(oout, oin, sbuf, arrays, 1);     // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, arrays, nbatches);
    return System.currentTimeMillis() - start;
}
 
Example 22
public static void test(Object a) {
    try {
        File objectbin = new File("object.bin");
        FileOutputStream fos = new FileOutputStream(objectbin);
        ObjectOutputStream out = new ObjectOutputStream(fos);
        out.writeObject(a);
        fos.close();
        FileInputStream fis = new FileInputStream(objectbin);
        ObjectInputStream in = new ObjectInputStream(fis);
        Object o = in.readObject();
        fis.close();
        System.err.println(o);
    } catch (Throwable ex) {
        ex.printStackTrace();
        failed = true;
    }
}
 
Example 23
Source Project: joshua   Source File: BloomFilterLanguageModel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Builds a language model and stores it in a file.
 * 
 * @param argv command-line arguments
 */
public static void main(String[] argv) {
  if (argv.length < 5) {
    String msg = "usage: BloomFilterLanguageModel <statistics file> <order> <size>"
        + " <quantization base> <output file>";
    System.err.println(msg);
    LOG.error(msg);
    return;
  }
  int order = Integer.parseInt(argv[1]);
  int size = (int) (Integer.parseInt(argv[2]) * Math.pow(2, 23));
  double base = Double.parseDouble(argv[3]);

  try {
    BloomFilterLanguageModel lm = new BloomFilterLanguageModel(argv[0], order, size, base);

    ObjectOutputStream out =
        new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(argv[4])));

    lm.writeExternal(out);
    out.close(); //TODO: try-with-resources
  } catch (IOException e) {
    LOG.error(e.getMessage(), e);
  }
}
 
Example 24
Source Project: astor   Source File: XYCoordinateTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    XYCoordinate v1 = new XYCoordinate(1.0, 2.0);
    XYCoordinate v2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(v1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        v2 = (XYCoordinate) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(v1, v2);
}
 
Example 25
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    SymbolicXYItemLabelGenerator g1 = new SymbolicXYItemLabelGenerator();
    SymbolicXYItemLabelGenerator g2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(g1);
        out.close();

        ObjectInput in = new ObjectInputStream(
            new ByteArrayInputStream(buffer.toByteArray())
        );
        g2 = (SymbolicXYItemLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(g1, g2);
}
 
Example 26
Source Project: jdk8u_jdk   Source File: JScrollPane.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * See <code>readObject</code> and <code>writeObject</code> in
 * <code>JComponent</code> for more
 * information about serialization in Swing.
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    s.defaultWriteObject();
    if (getUIClassID().equals(uiClassID)) {
        byte count = JComponent.getWriteObjCounter(this);
        JComponent.setWriteObjCounter(this, --count);
        if (count == 0 && ui != null) {
            ui.installUI(this);
        }
    }
}
 
Example 27
Source Project: dremio-oss   Source File: IcebergSerDe.java    License: Apache License 2.0 5 votes vote down vote up
private static byte[] serializeToByteArray(Object object) throws IOException {
  try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(bos)) {
    out.writeObject(object);
    return bos.toByteArray();
  }
}
 
Example 28
Source Project: letv   Source File: ax.java    License: Apache License 2.0 5 votes vote down vote up
private void a(ObjectOutputStream objectOutputStream) throws IOException {
    try {
        b(new cs(new dk((OutputStream) objectOutputStream)));
    } catch (cf e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 29
Source Project: dragonwell8_jdk   Source File: Cons.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Run benchmark for given number of cycles.
 */
void doReps(StreamBuffer sbuf, Dummy dummy, int reps) throws Exception {
    OutputStream out = sbuf.getOutputStream();
    InputStream in = sbuf.getInputStream();
    for (int i = 0; i < reps; i++) {
        sbuf.reset();
        ObjectOutputStream oout = new ObjectOutputStream(out);
        oout.writeObject(dummy);
        oout.flush();
        ObjectInputStream oin = new ObjectInputStream(in);
        oin.readObject();
    }
}
 
Example 30
@Test
@Deployment
public void testJavaObjectNotDeserializedIfNotRequested() throws Exception {

  // this test makes sure that if a serialized value is set, it is not automatically deserialized if deserialization is not requested

  // given
  // a serialized Java Object
  FailingJavaSerializable javaSerializable = new FailingJavaSerializable("foo");
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  new ObjectOutputStream(baos).writeObject(javaSerializable);
  byte[] serializedObjectBytes = baos.toByteArray();
  String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(serializedObjectBytes), engineRule.getProcessEngine());

  thrown.expect(RuntimeException.class);
  thrown.expectMessage("Exception while deserializing object");

  // which cannot be deserialized
  ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(serializedObjectBytes));
  objectInputStream.readObject();

  // if
  // I start a process instance in which a Java Delegate reads the value in its serialized form
  runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables()
    .putValue("varName", serializedObjectValue(serializedObject)
      .serializationDataFormat(JAVA_DATA_FORMAT)
      .objectTypeName(JavaSerializable.class.getName())
      .create()));

  // then
  // it does not fail
}