How to read REST service that returns JSON object and store the same into PostgreSQL using Mule ESB, Mule Studio How to read REST service that returns JSON object and store the same into PostgreSQL using Mule ESB, Mule Studio json json

How to read REST service that returns JSON object and store the same into PostgreSQL using Mule ESB, Mule Studio


Since you want to store the whole JSON, there is no need to deserialize it as an object: I suggest you simply transform the HTTP-streamed payload into a java.lang.String and insert it as-is in the DB.

This would done like that:

<jdbc:postgresql-data-source name="PostgreSQL_Data_Source"    user="username" password="pwd" url="jdbc:postgresql://localhost:5432/TestDB"    transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source" /><jdbc:connector name="PostgreSQL_Connector" dataSource-ref="PostgreSQL_Data_Source"    validateConnections="true" queryTimeout="-1" pollingFrequency="0"    doc:name="Database">    <jdbc:query key="InsertRecord"        value="INSERT INTO "AnotherJSonTable"("StoreJsonObject") VALUES (CAST(#[message.payload] AS json))" /></jdbc:connector><flow name="testRestFlow1" doc:name="testRestFlow1">    <http:inbound-endpoint exchange-pattern="request-response"        address="http://localhost:8082/index.html" doc:name="HTTP" />    <http:rest-service-component httpMethod="GET"        serviceUrl="http://localhost:35798/RestServiceImpl.svc/json/567" />    <object-to-string-transformer />    <jdbc:outbound-endpoint exchange-pattern="one-way"        queryKey="InsertRecord" queryTimeout="-1" connector-ref="PostgreSQL_Connector"        doc:name="Database" /></flow>