Java Object Serialize serialize(Object objData, Class typeOfT)

Here you can find the source of serialize(Object objData, Class typeOfT)

Description

serialize

License

Open Source License

Declaration

public static <T> String serialize(Object objData, Class<T> typeOfT)
        throws UnsupportedEncodingException, IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

public class Main {

    public static <T> String serialize(Object objData, Class<T> typeOfT)
            throws UnsupportedEncodingException, IOException {
        String output;//from  w  ww.  ja v a2s.  c om
        if (objData == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        mapper.writeValue(os, typeOfT);
        output = new String(os.toByteArray(), "UTF-8");
        return output;
    }
}

Related

  1. serialize(Object obj)
  2. serialize(Object obj, String file)
  3. serialize(Object obj, String fileName)
  4. serialize(Object obj, String fileName)
  5. serialize(Object obj, String fname, boolean gzipped)
  6. serialize(Object object)
  7. serialize(Object object)
  8. Serialize(Object object)
  9. serialize(Object object)