Mapping a Base64-encoded byte array to a String

315 views
Skip to first unread message

Dhruva Reddy

unread,
Jan 31, 2013, 12:08:57 PM1/31/13
to dozer-...@googlegroups.com
I am invoking an XML-RPC service, from which I get the responses in the form of HashMap, which I am trying to map to a POJO.  There are a couple of fields that come back as Base64-encoded byte arrays, which I am trying to map to methods that decode those fields, and convert them to strings.

Source:
HashMap {"field": <Base64-encoded byte array>}

Destination:
public class Thing2 {
    private String field = null;

    public setField(String field) {
        this.field = field;
    }

    public void decodeField(String field) {
        this.field = new String(methodToDecodeWhichReturnsBytes(field.getBytes()));
    }

    public void decodeField(byte[] field) {
        this.field = new String(methodToDecodeWhichReturnsBytes(field));
    }
}

My mapping is as follows:

<mapping>
  <class-a>java.util.Map</class-a>
  <class-b>com.org.Thing2</class-b>
  <field>
    <a key="field">this</a>
    <b set-method="decodeField(java.lang.String)">field</b>
  </field>
</mapping>

This runs without error, but the value of "field" in the destination object is corrupted.  I tried setting "set-method" to "decodeField(byte[])", but I get an exception.  From what I can see in the logs, the byte array is converted to a String (which is why I added the decodeField(String) method), but I can't figure out exactly how (like, does it do its decoding?).

Does anyone have any insights on this?

Thanks,
Dhruva
Reply all
Reply to author
Forward
0 new messages