I have problem with WSO2 micro integrator: I have a dataservice with a method for saving data to the database. I pass data to the method via payload factory :
<payloadFactory media-type="json">
<format>
{
"_postauthor": {
"id": "$1",
"name": "$2",
"birth_date": "$3",
}
}
</format>
<args>
<arg evaluator="json" expression="$.id"/>
<arg evaluator="xml" expression="get-property('name')"/>
<arg evaluator="json" expression="$.birth_date"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/ -->
My data service definition
<data name="RESTDataService" transports="http https">
<description>AdastraApp REST Data service </description>
<config id="AdastraAppDataSource">
...
</config>
<resource method="POST" path="author">
<description />
<call-query href="CreateAuthor">
<with-param name="id" query-param="id" />
<with-param name="name" query-param="name" />
<with-param name="birth_date" query-param="birth_date" />
</call-query>
</resource>
<query id="CreateAuthor" useConfig="AdastraAppDataSource">
<sql>INSERT INTO authors (id, name, birth_date) VALUES (:id, :name, CAST(:birth_date AS DATETIME))</sql>
<param type="IN" name="id" optional="false" paramType="SCALAR" sqlType="STRING" defaultValue="NULL" />
<param type="IN" name="name" optional="true" paramType="SCALAR" sqlType="STRING" defaultValue="NULL" />
<param type="IN" name="birth_date" optional="true" paramType="SCALAR" sqlType="TIMESTAMP" defaultValue="NULL" />
</query>
</data>
If I call the data service method with payload
{
"_postauthor": {
"id": "001482af-b42f-41b8-884d-6109954d81f9",
"name": "Madeline Miller",
"birth_date": "1978-01-01T00:00:00.000Z",
}
}
I got from Micro Integrator server response :
[2025-02-05 03:15:09,478] ERROR {GsonXMLStreamReader} - Value type miss match, Expected value type - 'dateTime', but found - 'STRING'[2025-02-05 03:15:09,478] ERROR {ServerWorker} - Error processing POST request for : /services/RESTDataService/author. java.lang.IllegalArgumentException: Value type miss match, Expected value type - 'dateTime', but found - 'STRING'at org.apache.axis2.json.gson.GsonXMLStreamReader.nextValue(GsonXMLStreamReader.java:750)at org.apache.axis2.json.gson.GsonXMLStreamReader.readValue(GsonXMLStreamReader.java:625)at org.apache.axis2.json.gson.GsonXMLStreamReader.stateTransition(GsonXMLStreamReader.java:531)at org.apache.axis2.json.gson.GsonXMLStreamReader.next(GsonXMLStreamReader.java:177)at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)at org.apache.axiom.om.impl.llom.OMSerializableImpl.build(OMSerializableImpl.java:78)
Please show me what i do wrong. Thank you
I have problem with WSO2 micro integrator: I have a dataservice with a method for saving data to the database. I pass data to the method via payload factory :
<payloadFactory media-type="json">
<format>
{
"_postauthor": {
"id": "$1",
"name": "$2",
"birth_date": "$3",
}
}
</format>
<args>
<arg evaluator="json" expression="$.id"/>
<arg evaluator="xml" expression="get-property('name')"/>
<arg evaluator="json" expression="$.birth_date"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/ -->
My data service definition
<data name="RESTDataService" transports="http https">
<description>AdastraApp REST Data service </description>
<config id="AdastraAppDataSource">
...
</config>
<resource method="POST" path="author">
<description />
<call-query href="CreateAuthor">
<with-param name="id" query-param="id" />
<with-param name="name" query-param="name" />
<with-param name="birth_date" query-param="birth_date" />
</call-query>
</resource>
<query id="CreateAuthor" useConfig="AdastraAppDataSource">
<sql>INSERT INTO authors (id, name, birth_date) VALUES (:id, :name, CAST(:birth_date AS DATETIME))</sql>
<param type="IN" name="id" optional="false" paramType="SCALAR" sqlType="STRING" defaultValue="NULL" />
<param type="IN" name="name" optional="true" paramType="SCALAR" sqlType="STRING" defaultValue="NULL" />
<param type="IN" name="birth_date" optional="true" paramType="SCALAR" sqlType="TIMESTAMP" defaultValue="NULL" />
</query>
</data>
If I call the data service method with payload
{
"_postauthor": {
"id": "001482af-b42f-41b8-884d-6109954d81f9",
"name": "Madeline Miller",
"birth_date": "1978-01-01T00:00:00.000Z",
}
}
I got from Micro Integrator server response :
[2025-02-05 03:15:09,478] ERROR {GsonXMLStreamReader} - Value type miss match, Expected value type - 'dateTime', but found - 'STRING'[2025-02-05 03:15:09,478] ERROR {ServerWorker} - Error processing POST request for : /services/RESTDataService/author. java.lang.IllegalArgumentException: Value type miss match, Expected value type - 'dateTime', but found - 'STRING'at org.apache.axis2.json.gson.GsonXMLStreamReader.nextValue(GsonXMLStreamReader.java:750)at org.apache.axis2.json.gson.GsonXMLStreamReader.readValue(GsonXMLStreamReader.java:625)at org.apache.axis2.json.gson.GsonXMLStreamReader.stateTransition(GsonXMLStreamReader.java:531)at org.apache.axis2.json.gson.GsonXMLStreamReader.next(GsonXMLStreamReader.java:177)at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)at org.apache.axiom.om.impl.llom.OMSerializableImpl.build(OMSerializableImpl.java:78)
Please show me what i do wrong. Thank you
Share Improve this question asked Feb 6 at 13:10 PospiPospi 11 bronze badge New contributor Pospi is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1- Can you try setting the sqlType of "birth_date" as string in your above dataservice and try again? (No need to change in the database.) – Arunan Commented Feb 8 at 15:44
1 Answer
Reset to default 0The above issue occurs due to the mismatch of the data types. In the JSON payload, it sends the "birth_date" field as a STRING but in the data-service end, it expects a value for "birth_date" as TIMESTAMP. But in the database side, it can store TIMESTAMP values that are sent as STRINGs by internally processing to the TIMESTAMP format.