Custom serialization - could you do this?

Hi
I'll describe a partially hypothetical situation to allow me to ask the questions I want with some context.
Let's say someone gave you the responsibility of implementing the following API with the specified contract:
* Convert <code>object</code> to a serialized format and save in the file
* <code>saveDestination</code>. You are free to choose the serialization format.
public void serializeAndSave(java.io.Serializable object, java.io.File saveDestination);
* Deserialize objects serialized by the <code>serializeAndSave()</code> method.
public java.io.Serializable deserialize(java.io.File file);
Additionally, let's say the following were conditions and restrictions were specified by the person asking you to implement these methods:
* The version of the class for <code>object</code> or any of the super-classses in its class hierarchy or the type of any fields will never change.
* The fields of <code>object</code> will probably be private. Fields consistent with the java.io.Serializable contract, must be serialied (for instance, transient fields do not need to be serialized).
* You will never have any information about how any declared methods in <code>object</code> relate to declared fields, so you cannot rely on declared methods for getting field values when serializing or setting field values when deserializing.
* You will never have information about how parameters in declared constructors relate to declared fields, so you cannot rely on declared constructors for setting field values when deserializing.
* Besides the java.io.Serializable interface and the contract specified by Java when implementing the Serializable interface (eg. empty constructor), <code>object</code> will not necessarily conform to any interface or API that you will have prior knowledge of.
* <code>object</code> may have an inheritance hierarchy to any depth. Super-classes in the class hierarchy may have fields too.
* Super-classes in the object hierarchy, and their fields, are subject to the same conditions and constraints described here for <code>object</code>
OK, there's a description of the hypothetical task someone has asked you to complete.
Luckily, this is very easy to do. You can simply rely on Java's inbuilt serialization mechanisms. You can use java.io.ObjectOutputStream and java.io.ObjectInputStream - it's all very easy. Java's inbuilt serizlization/deserialization has no problem with private fields and no problems with super-classe fields even if private.
Now let's say I changed your task by changing the contract for the serializeAndSave() method as follows:
* Convert <code>object</code> to an XML serialization format and save in the file
* <code>saveDestination</code>.
public void serializeAndSave(java.io.Serializable object, java.io.File saveDestination);
Notice that the class must now be serialized in XML format*.
How would you implement the serializeAndSave() and deserialize() methods now? In particular:
* In serialzeAndSave(), how would you obtain the values of private fields in any of the super-classes in the object hierarchy?
* In deserialize(), assuming you succussfully implemented the serializeAndSave() method, how would you set the value of any of the private fields in <code>object</code> or any of the super-classes in <code>object</codes>'s class hierarchy?
Cheers.

>>>
What you're proposing is a feeble solution, but if you insist on using it, it's genuinely laughably trivial to implement. What have you been doing for the last 15 years?
<<<
Yeah been getting that a lot. Funny thing is, no-one can back it up.
Here's your opportunity for you to show that you are right and I a wrong. Provide the implementation for showValueOfA(), setValueOfA(), setValueForB(). I'll go out on a limb right now and tell you that you cannot do it, despite you trying to make out that you have a complete understanding of the technical issue at hand.
package com;
import java.lang.reflect.Field;
public final class DisplayUnderstanding{
     public static void showFields(Data data){
          Class clazz = null;
          Field[] fields = null;
          Field field = null;
          clazz = data.getClass();
          fields = clazz.getDeclaredFields();
          for(int i = 0, n = fields.length; i < n; ++i){
               field = fields;
               System.out.println(field.getName() + ": " + field.getType());
     * Will write to <code>System.out</code> the value of the field <code>a</code>
     * in the instance <code>data</code>.
     public static void showValueOfA(Data data){
          /* IMPLEMENTATION REQUIRED */
     * Will change the value of the field <code>a</code> in the instance
     * <code>data</code> to <code>value</code>.
     public static void setValueOfA(Data data,int value){
          /* IMPLEMENTATION REQUIRED */
     * Will change the value of the field <code>b</code> in the instance
     * <code>data</code> to <code>value</code>.
     public static void setValueOfB(Data data,int value){
          /* IMPLEMENTATION REQUIRED */
     public static class Data extends AbstractData{
          private int b = 0;
          public Data(int a,int b){
               super(a);
               this.b = b;
     public static abstract class AbstractData{
          private int a = 0;
          public AbstractData(int a){
               this.a = a;

Similar Messages

  • Moderators could you add this to the Help & Terms of Use

    Hello,
    I just found it interesting that this was not included in the Help & Terms of Use information. Could you add, the next time they are updated, the time limit a user has to edit a post. I have seen this a number of times come up in the Discussions and it always leads to some confusion as to just how long a user has to edit their post. My apologies if it is there and I just didn't find it...it wouldn't be the first time.
    I hope you find this constructive feedback for a future update to the Help & Terms of Use. Sorry if this has already been requested as I hadn't seen it.
    regards,
    littleshoulders
    Message was edited by: littleshoulders

    In the isshell in ifs 1.1.9, I do a
    ls -attrall
    and I see "null" next to the property bundle. I assume this to mean that no property bundle has been created for this folder instance.
    As for categories, 1.2 doc states.. "A folder, ... can be associated with zero,one or more categorys" I will have to create a new category for each file and or folder.
    I really want to have additional attributes for each file.
    I dont want to subclass folder because, if a user does a drag and drop in NTFS a folder will be created and not a MyFolder.
    I have a kludge for now; I put a comma delimited list of items in description field.
    Apparently this limitiation, is changed in 1.2. See above.
    Thanks for your help. IFS is a really great product. Cant wait for 1.2 on NT.
    Mitch
    null

  • Could you help this query

    hi to all
    i have table called period which has the four columns id(p.key),name,parent_id,level
    i have 3 different types of periods for eg
    101 2009 null 1
    102 Q1 101 2
    103 Jan 102 3
    so here parent_id is also a period , and have Q1,Q2,Q3,Q4 belong to level 2 and all the months belong to level 3
    Q1 has Jan,Feb,March and Q2 has Apr,May,Jun, .... Q4 has Oct,Nov,Dec months as childs
    now my question is to show the data for a year 2009 l
    displaying 2nd level and immeadetly its sub childs to it like
    id              name        level
    1096     Q1     2
    1097     JAN     3
    1098     FEB     3
    1099     MAR     3
    1100     Q2     2
    1101     APR     3
    1102     MAY     3
    1103     JUN     3
    1104     Q3     2
    1105     JUL     3
    1106     AUG     3
    1107     SEP     3
    1108     Q4     2
    1109     OCT     3
    1110     NOV     3
    1111     DEC     3
    1676     Annual     2( which does not have any more childs but still it is a child of 2009)
    1675     N/A     2( which does not have any more childs but still it is a child of 2009)
    thanks and regards
    santhosh

    if I understand correctly this is all bout ordering the data. So we just have to find the correct order by clause.
    Since you order by a date the basic principle is to convert all the differnt strings into a date value. Then order on it.
    example untested
    order by case when level = 3 then to_date(name,'MON')
                 when level = 2 and name like 'Q%' then add_months(to_date('0101','ddmm'),(to_number(substr(name,2,1))-1)*3) 
                 when level = 2 and name = 'Annual' then to_date('3112','ddmm')
                 when level = 2 and name = 'N/A' then to_date('3112','ddmm')
                 when level = 1 then to_date('YYYY')
                 end,
                 levelyou can also create a kind of hierarchical select, but I doubt that this would be faster.
    My prefered solution would be to add an additional column of datatype date. Fill it with the correct days and then order on it and on the level.
    Btw: With your result data you could order simply on ID, but I doubt if this can be guaranteed. So I do not recommend it.
    Edited by: Sven W. on Sep 23, 2009 10:06 AM - corrected level 3 function

  • This is a great tool Adobe team! Could you include this idea?...

    Hi Adobe team
    Great tool guys!
    Would it be possible to add a collaboration area for potential writers to use that want to locate other like minded writers?
    Regards
    Alan

    Thanks for your feedback Alan.
    You could post on our facebook page to find out other Story users and collaborators:
    http://www.facebook.com/adobestory/
    --Anubhav

  • Could you resolve this

    When i try to login through sqlplus for a user i get the following error:
    ERROR:
    ORA-12154: TNS:could not resolve the connect identifier specified.
    i am able to login through Oracle Exterprise Manager and Toad using the same user.
    Please Suggest.

    What's the workaround for this..A password is subject to Oracle naming conventions. But we can use special characters in a password in the same way that we can use them in table names, by wrapping the password in double quotes. This means that we have to use double quotes every time we attempt to connect...
    SQL> conn system
    Enter password: **********
    Connected.
    SQL> create user abc identified by "abc@789"
      2  /
    User created.
    SQL> grant create session to abc
      2  /
    Grant succeeded.
    SQL> conn abc/"abc@789"
    Connected.
    SQL> Cheers, APC

  • Could you correct this 4-lines-script please?

    Hi guys!
    I've some troubles with this script...
    [CODE]
    tell application "iTunes"
    set some_items to the selection
    do shell script "chmod a-w " & quoted form of POSIX path of (some_items as alias)
    end tell
    [CODE]
    Where is the fatal error? (In Finder it works succesfully..)
    Tks in advance..:))

    You can directly edit a file in AppleScript, for example:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;">
    set someLyrics to "blah blah blah
    blah blah blah"
    set theFile to (path to desktop as text) & "test.txt"
    set fileRef to (open for access file theFile with write permission) --fileRef is used to reference the file
    write ((current date) as text) to fileRef
    write return to fileRef
    write someLyrics to fileRef
    close access fileRef --be sure to close the file </pre>
    If you want to append to an existing file, you need to write beyond the existing contents (eof=end of file):
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;">
    set someLyrics to "blah blah blah
    blah blah blah"
    set theFile to (path to desktop as text) & "test.txt"
    set fileRef to (open for access file theFile with write permission) --fileRef is used to reference the file
    write ((current date) as text) to fileRef starting at eof
    write return to fileRef starting at eof
    write someLyrics to fileRef starting at eof
    close access fileRef --be sure to close the file </pre>
    There's quite a bit more to this subject, but if you need to ask further questions I would encourage you to post these separately to get the widest audience / quickest response.

  • You no longer have access to this service. Please contact Adobe Customer Support if you believe this is an error

    I believe this is an error.
    Cannot log onto my behance profile now, member since 2012..
    Kresimir Jelusic on Behance

    Hello - are you able to login now? This was a temporary glitch that should now be resolved!

  • Customer Support: Can you identify this text message?

    Hi,
    Can someone from Verizon tell me why I got the following text and what it means:
    "//VZWVVM:SYNC:ev=NM;id=1;c=1;t=v;s=My Home Phone Number Here;dt=18/11/2014 14:53 -0500;l=9;dev_t=5"
    I have had 3 such undecipherable messages in the past few days (all a little different). They appear to be coming from Verizon.
    Thanks

    Yesterday afternoon I called my cell phone from a land line phone to leave a message to test the voice mail feature of the cell phone. The text I received, posted above, is a result of that voice message. It came in right after I left the voice message. I did not get an indication on my cell phone of that voice mail until this morning when I turned the phone on.
    It is still not clear to me why I got the text, or why it took so long for my cell phone to indicate that I had a voice message.

  • HI could you solve this query

    Ex: Table : inputval
    Column: inputvalue VARCHAR2(100)
    DATA for above column are
    TCC=0471/12345/0999/8548/4321,VT=15,PRIMDX=false,DUR=365,VISITS=0
    values termination are '/'
    Q: i need to after TCC value from the inputvalue column
    i need 6 values output are below
    1. 471
    2. 12345
    3. 0999
    4. 8548
    5. 4321
    6. null
    i written query but i am not able to get these output
    i am giving sample query which i tried for one value
    SELECT
    case when inputvalue like '%TCC=%' then
    substr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),1,
    instr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),'/')-1) end tcc1,
    case when inputvalue like '%TCC=%' then
    substr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),
    instr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),'/')+1,
    instr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),'/',2)-1) end tcc2
    FROM inputval
    please solve me as early as possible
    Thanks,
    krish

    Hi,
    REGEXP_SUBSTR ( s
                  , '[^,]+'
                  , 1
                  , n
                  )returns the nth item in a comma-delimited list s. (It retuirns NULL if there are not that many items.)
    Cross-join with a counter table to get the values for n, and test if the nth item is the one that starts with 'TCC='.
    Depending on you data, it might be easier to use REGEXP_SUBSTR or REGEXP_REPLACE to find the part of the string between 'TCC=' and the next comma. (I can't tell from the one row of sample data.)
    Once you have the TCC-substring, use REGEXP_SUBSTR again to get the m-th item from the /-delimited list. (Use a different counter table.)
    If you need more help, post some more test data and desired results, testing any special cases, such as:
    two or more 'TCC=' items in one string
    NULL entries ('TCC=1///4')
    Misplaced label ('1/2/TCC=3/4/5')
    malformed numbers ('TCC=1.0.0/4')
    REGEXP_ function only work in Oracle 10 and up.

  • Could you check this code ??

    Hi Guyz,
      Here is my piece of code.
    FORM get_infotype_data TABLES pi_it0001_tbl      TYPE  t_it0001_tbl
                                  pi_emp_info_tbl    TYPE  t_emp_info_tbl
                                  pi_event_dates_tbl TYPE  t_event_dates_tbl
                                  po_emp_tab_tbl     TYPE  t_emp_tab_tbl.
      DATA: l_it0001_tbl   TYPE t_it0001_tbl,
            l_it0001_str   TYPE t_it0001_str,
            l_emp_info_tbl TYPE t_emp_info_tbl,
            l_emp_info_str TYPE t_emp_info_str,
            l_event_dates_str TYPE t_event_dates_str,
            l_emp_tab_tbl  TYPE t_emp_tab_tbl,
            l_emp_tab_str  TYPE t_emp_tab_str.
      SORT: pi_it0001_tbl      BY  pernr,
            pi_emp_info_tbl    BY  pernr,
            pi_event_dates_tbl BY  pernr.
      LOOP AT pi_it0001_tbl INTO l_it0001_str.
        READ TABLE pi_emp_info_tbl
        WITH KEY pernr = l_it0001_str-pernr BINARY SEARCH.
        IF sy-subrc = 0 .
        clear l_emp_info_str.
          MOVE: l_emp_info_str-perid TO l_emp_tab_str-perid,
                l_emp_info_str-gbdat TO l_emp_tab_str-gbdat.
          CASE l_emp_info_str-gesch.
            WHEN '1'.
              MOVE 'M' TO l_emp_tab_str-gesch.
            WHEN '2'.
              MOVE 'F' TO l_emp_tab_str-gesch.
          ENDCASE.
        ENDIF.
        READ TABLE pi_event_dates_tbl WITH KEY pernr = l_it0001_str-pernr
        BINARY SEARCH.
        IF sy-subrc = 0.
          MOVE: l_event_dates_str-betrg TO l_emp_tab_str-betrg.
        ENDIF.
        MOVE l_emp_tab_str TO po_emp_tab_tbl.
      ENDLOOP.
    ENDFORM.                                         " get_infotype_data
    I am not getting any data in to the table po_emp_tab_tbl.
    After rwading the table,  Getting sy-subrc = 0.
    Please help me.

    1. structure for both l_emp_tab_str and  po_emp_tab_tbl are different.
    2. move one by one field to dest. structure.
    3. check whether data is populating in the l_emp_tab_str .
    4. as well as in int. table pi_it0001_tbl.
    5. u defined the stru. for po_emp_tab_tbl as a work area.
    wheterh it should be work area or table?
    if its table, define table type

  • I have already rest all computers this year but have new computer can you rest this please

    Hi
    I had a computer that i had to keep factory resetting. i had to do the deautherize all computer thing but i got a new computer and i need to do it again. could you rest this for me please
    thanks fraser

    You log into them through VNC and individually deauthorize them, or click here and request assistance.
    (66754)

  • Why GWt suggest box is not working in the latest versions of Firefox ? It was working only in Firefox 3 and not other versions. could you please assist in this regards.,

    Why GWt suggest box is not working in the latest versions of Firefox ?
    It was working only in Firefox 3 and not other versions. could you please assist in this regards.,

    jbren wrote:
    I repeatedly have problems with playback on my STB's. Go thru all the motions, inhouse agent, fix multi room dvr problems. Unplug unit, unplug dvr, etc. etc. etc.  The DVR'd show will play on the DVR but not on the STB's. What's up with that?
    Sorry to hear the auto fix suggested early did not fix your problem. So we can get more information from you, I have copied your post to our private support board. Please refer all correspondences to there from here on out. You can easily get to the private support one of two ways. In the email you signed up for the forums with, you will receive a link to click on. Make sure you are already signed into the forums before clicking on this link. Another way of getting there is by clicking on your username anywhere you see it in the forums. This brings you to your account profile. Scroll down to the section labeled "My Support Cases" . In there you will see the link to your case.
    Anthony_VZ
    **If someones post has helped you, please acknowledge their assistance by clicking the red thumbs up button to give them Kudos. If you are the original poster and any response gave you your answer, please mark the post that had the answer as the solution**
    Notice: Content posted by Verizon employees is meant to be informational and does not supersede or change the Verizon Forums User Guidelines or Terms or Service, or your Customer Agreement Terms and Conditions or plan

  • Could you please stop this abo?

    Could you please stop this abonnement? my email is: [email protected] and I´m from germany. So if you read this, please stop this abo! thank you very much.

    We can't do this via the forum. You need to contact Customer Support.
    https://www.acrobat.com/misc/en/contact-support.html

  • Since my last Photoshop BRIDGE update and PS CC2014,. My PS C6 is Perturbed. I can't not open  all filles. PS Will open with  the CC 2014 This OK.But I don't have all my Plug ins. Could you setting All My Plug ins in PSCC2014

    Since my last Photoshop BRIDGE update,. My PS C6 is Perturbed.
    I can't not open  all fills. PS  open the CC 2014 This OK.But I don't have all my Plug ins
    Could you setting to All My Plug ins in PSCC2014.
    The Others.:
    I can't Install Photoshop Air .
    Will you please help me
    <Removed by Moderator>

    Moving this discussion to the Photoshop General Discussion forum.
    Nicolas1944 please be aware that you are posting in a public forum.  I have removed your e-mail address from your previous post.  You can also work directly with a member of our support team at Contact Customer Care.
    The community in the Photoshop General Discussion forum should be able to help with your current difficulties opening files in Photoshop CC 2014.

  • Could you please send me the links to get an idea on Custom table controls

    Hi Friends,
               I am working on custom table controls, Could you please send me any links on Custom table controls or documentation.
       Thanks and Regards,
       Sandeep Kumar Bonam

    Hello Sandeep,
    See here for the latest table features in 2004s.
    <a href="/people/bertram.ganz/blog/2006/07/03/web-dynpro-java-foundation--whats-new-in-sap-netweaver-2004s:///people/bertram.ganz/blog/2006/07/03/web-dynpro-java-foundation--whats-new-in-sap-netweaver-2004s
    This link also has a lot information on tables
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/d43bb0e5-0601-0010-3a97-d9760726bf4c">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/d43bb0e5-0601-0010-3a97-d9760726bf4c</a>
    Regards,
    Sudeep.

Maybe you are looking for

  • Entity type "EJB-JAR" may not be used in public part "ejbjar_api"

    Experts, Can you please help me to identify why the error 'Entity type "EJB-JAR" may not be used in public part "ejbjar_api", unsupported purpose.' appears on NWDS while creating a project on a DC and how can this be resolved. Thanks in advance -Lave

  • Nokia Ovi backup didn't work

    I have Nokia E6 and my bluetooth was not working fine so I reset the factory default settings and before that I took the back up, but once I restore all the settings everything was restored except msgs in which I made several folders. It say zero (0)

  • SoCo - Replace with Catalog Item SC: CATALOGID field not updated

    Hi All: We are in SRM 7.0 and ECC 6 Classic Scenario In our PDP business scenario, PReq's from ECC goes to SoCo and we replace some requirements with Catalog Item. The issue for our compliance reporting the SC table:BBP_PDIGP field: CATALOGID is not

  • Adobe Reader Performance with Protect Mode On

    We are getting very poor performance in opening PDF documents with Adobe Reader XI with Protected Mode on, particularly for users remote from our central server.  With Protected Mode off, performance is much better (10-20X faster opening).  Note that

  • EPMA installation 11.1.1.3

    Hi, Can i install EPMA 11.1.1.3 on weblogic 10g? does weblogic 10g supports epma 11.1.1.3 suite? OS::windows 2003 sp1