tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Open Symphony Core > Encode Object

Encode Object 

OSCore (Open Symphony Core) is a java library with lot of utilities and reusable components. This requires the libraries oscore-2.2.6.jar, mail.jar to be in classpath. The following example shows using TextUtils.encodeObject() API. It encodes the given Object to String by serializing it to byte array and then encoding using Base64.

File Name  :  
com/bethecoder/tutorials/oscore/EncodeObjectTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.oscore;

import java.io.IOException;
import java.util.Arrays;

import com.opensymphony.util.TextUtils;

public class EncodeObjectTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {

    String encObj = TextUtils.encodeObject("ABCDEFG");
    System.out.println(encObj);
    
    encObj = TextUtils.encodeObject(new Double(1.2345678));
    System.out.println(encObj);
    
    encObj = TextUtils.encodeObject(Arrays.asList("ONE""TWO"));
    System.out.println(encObj);
  }

}
   

It gives the following output,
rO0ABXQAB0FCQ0RFRkc=

rO0ABXNyABBqYXZhLmxhbmcuRG91YmxlgLPCSilr+wQCAAFEAAV2YWx1ZXhyABBqYXZhLmxhbmcu
TnVtYmVyhqyVHQuU4IsCAAB4cD/zwMoqWx1d

rO0ABXNyABpqYXZhLnV0aWwuQXJyYXlzJEFycmF5TGlzdNmkPL7NiAbSAgABWwABYXQAE1tMamF2
YS9sYW5nL09iamVjdDt4cHVyABNbTGphdmEubGFuZy5TdHJpbmc7rdJW5+kde0cCAAB4cAAAAAJ0
AANPTkV0AANUV08=



 
  


  
bl  br