[JAVA] Convert Serializable Object to byte []


	public static byte[] toBytes(Serializable obj) {
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(baos);
			oos.writeObject(obj);
			byte[] data = baos.toByteArray();
			return data;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

Recommended Posts

Convert Serializable Object to byte []
Convert ruby object to JSON format
[Java] Convert Object type null to String type
19 Corresponds to object creation
How to convert a file to a byte array in Java
Convert Java Powerpoint to XPS
[Java] I want to convert a byte array to a hexadecimal number
I want to convert characters ...
Convert String type to Timestamp type
Convert a Java byte array to a string in hexadecimal notation
18 Corresponds to JSON-like object definitions
[Java] How to convert a character string from String type to byte type
Convert from ○ months to ○ years ○ months
How to convert Java radix
[Java] Convert ArrayList to array
Convert formulas to reverse Polish notation
Convert alphabet to 26 base + array length
Convert Map <K, V1> to Map <K, V2> (Convert Map Value)
Convert Markdown to HTML with flexmark-java
How to convert erb file to haml
I want to convert InputStream to String
[Java] Convert 1-to-N List to Map
How to convert LocalDate and Timestamp
Convert iso-2022-jp character string to utf-8
[Android] Convert Android Java code to Kotlin
[Small story] Convert Stream to Iterable
[Java] Convert array to ArrayList * Caution
Convert Swift 2D array to C 2D array