Java XML Data Type Converter serializeToString(Object object)

Here you can find the source of serializeToString(Object object)

Description

serialize To String

License

Open Source License

Declaration

public static String serializeToString(Object object) throws IOException 

Method Source Code

//package com.java2s;
/* (c) 2014 LinkedIn Corp. All rights reserved.
 * /*from  ww w  . jav  a  2s.c  o m*/
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
 * this file except in compliance with the License. You may obtain a copy of the
 * License at  http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied.
 */

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.ObjectOutputStream;

import javax.xml.bind.DatatypeConverter;

public class Main {
    public static String serializeToString(Object object) throws IOException {
        byte[] bytes = serializeToBytes(object);

        return DatatypeConverter.printBase64Binary(bytes);
    }

    public static byte[] serializeToBytes(Object object) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);

        oos.writeObject(object);
        oos.close();

        return bos.toByteArray();
    }
}

Related

  1. printZahl31(BigDecimal value)
  2. printZimmeranzahl(BigDecimal value)
  3. readKey(Reader reader, String algorithm)
  4. sendJson(URL url, String method, String data, String user, String password)
  5. serializeLogic(Serializable logic)
  6. serializeURLSafe(String string)
  7. stringToCalendar(String value)
  8. stringToData(String data)
  9. toBinaryKeyId(String keyId)