1

I have a JDBC Result set as List<Object[]> & need to convert it to List<ObjectType> in Spring boot.

// Input Object Array returned by below code
List<Object[]> resultObj = query.getResultList();
// Ex
resultObj[0][0] = new Integer(10);
resultObj[0][1] = "Test";
resultObj[0][2] = "Hello";

// Need map resultObj to List<ObjectType> below type

class ObjectType {
    //maps to Object[0]
    private Integer x;
    //maps to Object[1]
    private String y;
    //maps to Object[2]
    private String z;
}

Since object[] has over 18 elements, instead of mapping manually each index to field of POJO, i tried using Dozer.

<mapping>
        <class-a>java.lang.Object[]</class-a>
        <class-b>com.ObjectType</class-b>
        <field>
            <a>this[0]</a>
            <b>x</b>
        </field>
        <field>
            <a>this[1]</a>
            <b>y</b>
        </field>
</mapping>

I tried following this answer https://stackoverflow.com/a/26556413/350705, but output mapped object has below value - same value for all fields & address space as value

"x": "[Ljava.lang.Object;@2d716a1c",
"y": "[Ljava.lang.Object;@2d716a1c",
"z": "[Ljava.lang.Object;@2d716a1c",

Please suggest if there is any other configurable approach for this.

3
  • can you provide the sample values of List<Object[]> and the expected output. see if this helps you- stackoverflow.com/questions/8600724/… Commented May 5, 2020 at 9:35
  • @NKR: I have updated sample input & input type to question. Commented May 5, 2020 at 9:51
  • @NKR: I am trying to avoid that manual mapping suggested in that question's answer - stackoverflow.com/a/8601960/350705. Commented May 5, 2020 at 9:52

1 Answer 1

0

Try something below that might help. For explanation please refer this link https://sourceforge.net/p/dozer/discussion/452530/thread/012023da/

<mapping>
    <class-a>java.lang.Object[]</class-a>
    <class-b>com.ObjectType</class-b>
    <field>
        <a>this</a>
        <b set-method="add(java.lang.Object)" type="iterate">anything</b>
        <b-hint>your destination object type</b-hint>
    </field>

Sign up to request clarification or add additional context in comments.

1 Comment

The Dozer content on SourceForge is outdated. Dozer has moved to GitHub dozermapper.github.io

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.