JiBX
  1. JiBX
  2. JIBX-224

Ability to unmarshall to an already instantiated object

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Patch Submitted:
      Yes
    • Number of attachments :
      2

      Description

      Adid the ability to unmarshall to an already instantiated object.

      This is particularly useful for the Struts2 RESTful plug in.

      1. IUnmarshallingContext.java
        13 kB
        Jon Little
      2. UnmarshallingContext.java
        130 kB
        Jon Little

        Activity

        Hide
        Dennis Sosnoski added a comment -

        You can already unmarshal to an existing object by casting it to IUnmarshallable (which interface will be added to the class by the binding compiler if it has a concrete global mapping), then calling the unmarshal() method of that interface. Is there a reason you can't use this approach, and need to have it as part of the context API?

        Show
        Dennis Sosnoski added a comment - You can already unmarshal to an existing object by casting it to IUnmarshallable (which interface will be added to the class by the binding compiler if it has a concrete global mapping), then calling the unmarshal() method of that interface. Is there a reason you can't use this approach, and need to have it as part of the context API?
        Hide
        Jon Little added a comment -

        I can use that approach and have just switched to using it.

        I merely did not know that this facility existed.

        Show
        Jon Little added a comment - I can use that approach and have just switched to using it. I merely did not know that this facility existed.
        Hide
        Jon Little added a comment -

        Having implemented the pre-scribed way to unmarshall to an already instantiated object I really really do not like having an uncondityional cast in my code:

        /**

        • @see org.apache.struts2.rest.handler.ContentTypeHandler#toObject(java.io.Reader, java.lang.Object)
          */
          public void toObject(Reader in, Object target)
          {
          init();

        try

        { IUnmarshallingContext umc = bf.createUnmarshallingContext(); umc.setDocument(in); // This un-conditional cast is the current way that JibX unmarshalls to an // already instantiated object - YUCK ((IUnmarshallable)target).unmarshal(umc); }

        catch (JiBXException e)

        { log.error("Problem while unmarshalling XML to an object"); log.error(e.getMessage()); log.error(e.getStackTrace()); }

        }

        Therefore I would really like to see my new methods added to the context API.

        BTW, I did have an instanceof test but that failed for reasons that I could only deduce to how the byte code is altered

        Show
        Jon Little added a comment - Having implemented the pre-scribed way to unmarshall to an already instantiated object I really really do not like having an uncondityional cast in my code: /** @see org.apache.struts2.rest.handler.ContentTypeHandler#toObject(java.io.Reader, java.lang.Object) */ public void toObject(Reader in, Object target) { init(); try { IUnmarshallingContext umc = bf.createUnmarshallingContext(); umc.setDocument(in); // This un-conditional cast is the current way that JibX unmarshalls to an // already instantiated object - YUCK ((IUnmarshallable)target).unmarshal(umc); } catch (JiBXException e) { log.error("Problem while unmarshalling XML to an object"); log.error(e.getMessage()); log.error(e.getStackTrace()); } } Therefore I would really like to see my new methods added to the context API. BTW, I did have an instanceof test but that failed for reasons that I could only deduce to how the byte code is altered
        Hide
        Dennis Sosnoski added a comment -

        I don't think this change is justified at present, though I'll keep it in mind for 2.0.

        Show
        Dennis Sosnoski added a comment - I don't think this change is justified at present, though I'll keep it in mind for 2.0.

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Jon Little
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: