Deserializing A Bean From XML

 
 
This java source code is about Deserializing a Bean from XML......
 
 
  1. // Deserialize an object

  2.     try {

  3.         XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(

  4.             new FileInputStream("infilename.xml")));

  5.    

  6.         // MyClass is declared in e7 Serializing a Bean to XML

  7.         MyClass o = (MyClass)decoder.readObject();

  8.         decoder.close();

  9.    

  10.         // Use the object

  11.         int prop = o.getProp();     // 1

  12.         int[] props = o.getProps(); // [1,2,3]

  13.     } catch (FileNotFoundException e) {

  14.     }

  15.  

  16. Here is the XML data being deserialized:

  17.     <?xml version="1.0" encoding="UTF-8"?>

  18.     <java version="1.4.0" class="java.beans.XMLDecoder">

  19.         <object class="MyClass">

  20.             <void property="prop">

  21.                 <int>1</int>

  22.             </void>

  23.             <void property="props">

  24.                 <array class="int" length="3">

  25.                     <void index="0">

  26.                         <int>1</int>

  27.                     </void>

  28.                     <void index="1">

  29.                         <int>2</int>

  30.                     </void>

  31.                     <void index="2">

  32.                         <int>3</int>

  33.                     </void>

  34.                 </array>

  35.             </void>

  36.         </object>

  37.     </java>
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 17th Feb 2007
  Rating : No Rating
  Accessed  :  5387
  Submitted by :  javabill
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related JSP Source Codes
  • Spring
  • Wraps a string to a given number of characters using a string break character
  • Uppercase the first character of each word in a string
  • Make a string's first character uppercase
  • Strip whitespace (or other characters) from the beginning and end of a string

  • Copyright © 2013 VisualBuilder. All rights reserved

    Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

    Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0