deserialization - Deserialize a String into a Field Type Java -
I am currently working with the Zedish database library and a Hashmap.
I need a method to deserialize a class from a Hashmap, will not use any datatype except for the target class string and primitive datatype.
This is what I have currently found:
public stable
But if there is one other option than using a huge? < / P>
The solution provided by Rishan was:
The answer to which is asked is a great solution (@ Luigi R. Viggioyo).
Package data; Import java.beans.PropertyEditor; Import java.beans.PropertyEditorManager; Import java.lang.reflect.Field; Import java.util.HashMap; Import java.util.Map; Public Class Reflections {/ ** * @ Ultimate Oz * * Ruran * @ Throws InvalidArgument Exception * @ Throwav Invalid Access Access / Public Stabilizer & lt; T & gt; Click the & lt; String, string & gt; Serialize (last T-OBJ) executed illegally, exception, IllegalAccessException {// local variable Boolean flag; Field on; Click the & lt; String, string & gt; Map = new hashmap & lt; String, string & gt; (); // Load required data class & lt; Object & gt; ObjClass = obj.getClass (); Field [] field = objClass.getDeclaredFields (); // Go to {current = fields [i] for each field (int i = 0; i & lt; fields.length; i ++); // Flag Flag Check = Current. enter (); // Make it accessible if (! Flag) {current.setAccessible (true); } // Map Member on map. Input (field [i] .getName (), field [i] .get (object) obj) .toString ()); // Reset flag is set (! Flag) {current.setAccessible (false); }} Return map; } / ** * @ Ultimate Ozzy @ Permanent Map * @ Throwage InvalidException Exception * @ Throws Invalid Invalid Access * / Public Stabilizer & lt; T & gt; Waste deserialize (last T ozje, last map & lt; string, string & gt; map) is sold illegally, IllegalAccessException {// local variable Boolean flag; Field on; // Load required data class objClass = obj.getClass (); Field [] field = objClass.getDeclaredFields (); // Go to {current = fields [i] for each field (int i = 0; i & lt; fields.length; i ++); // Flag Flag Check = Current. enter (); // Make it accessible if (! Flag) {current.setAccessible (true); } // Set a member from the map key and change it to the desired type current.set (obj, convert (current.getType (), map.get (current.getName ())); // Reset flag if set (! Flag) {current.setAccessible (false);}}} / ** * @ Ultimate Goal Type * @ Ultimate Text * @Runan * / Personal Stable Object Convert (Class & lt;? & Gt; Target Type, String Text) {// Find the Editor for the desired type property editor editor = PropertyEditorManager.findEditor (targetType); // Load string editor. Settext (text); // Change the transformed form to the object return editor.GetValue ();}}
This is the ultimate solution for serialization and decierization. ProperyManager in some way is not available on Android so it Does not work on Android.
Comments
Post a Comment