WSO2: Can’t store JSON data in mongo “column” using REST. Works for SOAP. ERROR – GsonXMLStreamReader Value type miss match, Expected value type – ‘ ‘

94 views
0

I am trying to store some data into a MongoDB. Two of the fields are to store parts of a message, as some sort of a log.

When defining a dataservice I am asked to define what kind of data I expect in each one of the “columns”. I use quotes, as I am using a mongoDB. Everything works fine if I don’t insert JSON like data in any of those fields, but it fails as soon as I try to insert something in JSON format such as “MoreData”: {“subfield1″:”data6”}

It fails with REST but works with SOAP interfaces. An entire example of the data I am sending to the REST interface would be

{
“_postinsertnewmessage”: {

    "field1": "data1",
    "field2": "data2",
    "field3": "data3",
    "field4": "data4",
    "field5": {
        "Id": "id",
        "timestamp": "2017-12-09T09:47:23.294Z"},
        "morefields": "moredata"},
    "MoreData": {"subfield1":"data6"}
}

}

The error i get is the following:

ERROR – GsonXMLStreamReader Value type miss match, Expected value type – ”, but found – ‘STRING’
ERROR – ServerWorker Error processing POST reguest for : /services/MongoDBPortCDM/insertnewmessage. Error detail: Value type miss match, Expected value type – ”, but found – ‘STRING’.
java.lang.IllegalArgumentException: Value type miss match, Expected value type – ”, but found – ‘STRING’

On the other hand, the data I send to the soap interface that works is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">
   <soapenv:Header/>
   <soapenv:Body>
      <dat:_postinsertnewmessage>
         <dat:field1>data1</dat:field1>
         <dat:field2>data2</dat:field2>
         <dat:field3>data3</dat:field3>
         <dat:field4>data4</dat:field4>
         <dat:field5>{
            "Id": "id",
            "timestamp": "2017-12-09T09:47:23.294Z"},
            "morefields": "moredata"}</dat:field5>
         <dat:MoreData>{"subfield1":datasubfield1}</dat:MoreData>
      </dat:_postinsertnewmessage>
   </soapenv:Body>
</soapenv:Envelope>

This is successfully stored in the database.

Note that the REST version works if I try to store other data in field5 or MoreData as long as it is in “simple” SQL data types like Strings, integers… The problem comes when i try to store a whole JSON as a field. Is there a particular SQL type that i must use?

My intuition, though, is that the problem is with the MessageFormatter or the MessageBuilder, but i have no way of being certain. The problem seems to be when the message is being received by the REST interface and mapped to the DSS fields. This does not happen with SOAP.

Any advice is welcome!

Answered question
0

Hi I am facing issue while doing a json batch insert in wso2 post request. I am getting the error —-

{
    “Fault”: {
        “faultcode”: “soapenv:Server”,
        “faultstring”: “Value type miss match, Expected value type – ”, but found – ‘STRING'”,
        “detail”: “”
    }
}
However, If I insert a single record in json, the insert happens successfully and if I do a batch insert using xml payload, it works fine. The problem occurs only when I try to do batch insert in json format.
Here is my payload..

{
“_postaccounts_batch_req”: {
“_postaccounts”: [{

“account_id”: “123abc”,
“name”: “Will Smith”,
“user_name”: “will@smith.com”,
“description”: “Will Smith”,
“account_type” : “test”,
“balance” : “500.00”
},{
“account_id”: “123xyz”,
“name”: “Bill Smith”,
“user_name”: “bill@smith.com”,
“description”: “Bill Smith”,
“account_type” : “test”,
“balance” : “500.00”
}
]
}

}
Here is the stack trace

[2020-03-06 18:09:13,116] ERROR {org.apache.axis2.json.gson.GsonXMLStreamReader} – Value type miss match, Expected value type – ”, but found – ‘STRING’
[2020-03-06 18:09:13,116] ERROR {org.apache.synapse.transport.passthru.ServerWorker} – Error processing POST request for : /services/wso2_dataservice/accounts. java.lang.IllegalArgumentException: Value type miss match, Expected value type – ”, 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)….

I see in your post that you were able to successfully do batch insert with json payload, could you kindly help me on this issue.

Thanks

Edited answer
You are viewing 1 out of 1 answers, click here to view all answers.