CooperShelly
CooperShelly

Reputation: 123

How to transform a LinkedHashMap Payload to Object Payload in mule?

I want to transform a LinkedHashMap Payload to Object Payload in mule , i used the Byte Array to Object transformer but it dosent work for me , any idea guys ?

Upvotes: 0

Views: 4420

Answers (3)

Pierre B.
Pierre B.

Reputation: 12933

You seem to mention specifically the Object type. A LinkedHashMap is already an instance of Object: every Java instances inherit from the root class Object.

If you want to transform your HashMap into a specific object such as JSON or a custom object such as com.mycompany.CompData, you have several possibilities depending on your use case:

  • use DataWeave as mentioned in other answers (require EE)
  • use a built-in transformer such as Object-to-JSON
  • implement your own Transformer by extending AbstractTransformer

Se the docs for details: https://docs.mulesoft.com/mule-user-guide/v/3.8/using-transformers

If you may be more specific as to what your use case is I'll gladly refine my answer ;)

Upvotes: 0

Ashwin A Poojary
Ashwin A Poojary

Reputation: 1

You can use either dataweave or json to object transformer.

Upvotes: 0

Yevgeniy
Yevgeniy

Reputation: 2694

you can use dataweave to transform a payload of generic type (=java.util.Map) to a specific type (foo.bar.Type in the example):

%dw 1.0
%output application/java
---
payload as :object {
    class: "foo.bar.Type"
}

Upvotes: 1

Related Questions