1/* 2 * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* @test 25 * @bug 4180735 26 * 27 * @clean GetFieldWrite Foo TestClass 28 * @build GetFieldWrite 29 * @run main GetFieldWrite 30 * @clean GetFieldRead TestClass 31 * @build GetFieldRead 32 * @run main GetFieldRead 33 * 34 * @summary Make sure that fields that are defaulted can be of primitive and 35 * object type. 36 * 37 */ 38 39import java.io.*; 40class TestClass implements Serializable { 41 42 private static final long serialVersionUID = 5748652654655279289L; 43 44 // Fields to be serialized. 45 private static final ObjectStreamField[] serialPersistentFields = { 46 new ObjectStreamField("objectI", Integer.class)}; 47 48 Integer objectI; 49 int primitiveI; 50 Foo foo; 51 52 public TestClass(Foo f, Integer I, int i) { 53 foo = f; 54 objectI = I; 55 primitiveI = i; 56 } 57}; 58 59public class GetFieldWrite { 60 public static void main(String[] args) 61 throws ClassNotFoundException, IOException 62 { 63 FileOutputStream fos = new FileOutputStream("data.ser"); 64 ObjectOutput out = new ObjectOutputStream(fos); 65 out.writeObject(new TestClass(new Foo(100, 200), new Integer(100), 66 200)); 67 out.close(); 68 } 69}; 70 71/* 72 * Test class to be used as data field 73 */ 74class Foo implements Serializable{ 75 int a; 76 int b; 77 public Foo() { 78 a = 10; b= 20; 79 } 80 81 public Foo(int a1, int b1) 82 { 83 a = a1; b = b1; 84 } 85 86 public String toString() { 87 return new String("a = " + a + " b = " + b); 88 } 89} 90