0

Hi in wso2 ei in payload factory i am getting the response in json

<payloadFactory media-type="json">
<format>{
"Body":$1
}
</format>
<args>
<arg evaluator="json" expression="$."/>
</args>

And the Response is :

{
"Body":{
   "result":"done",
   "idNumber":"123",
   "address":{
      "local":"US",
      "abroad":"UK" 
    }
}
}

.... means multiple objects now what i need that all object first letter should be uppercase.

I need the below response

 {
    "Body":{
       "Result":"done",
       "IdNumber":"123",
       "Address":{
          "local":"US",
          "abroad":"UK" 
        }
    }
 }

Means only the object first letter should be capitalize...Any help!

Community
  • 1
  • 1
Chris Ryan
  • 11
  • 6
  • @amg_amit Can you please help me in this. – Chris Ryan Oct 09 '18 at 11:57
  • Sure @Chris Ryan , however before calling payload mediator how are you getting the argument $1, if you can try changing there then it should be easy, if you are unable to do so that we need to look into xslt mediator as payload mediator is not powerful enough for this. – amg_amit Oct 10 '18 at 07:59
  • @amg_amit thanks for your reply. well before payload is my wsdl endpoint in In Sequence which is giving me XML soap response and after that this is the payload and this payload is converting this into Json and display all data. – Chris Ryan Oct 10 '18 at 08:43
  • Who has created the wsdl is that your's or clients, if it is yours you can change the xsd which is being referred in wsdl, if it is client's then only option is to use xslt mediator over payload mediator, can you give me the same response after wsdl so that i can try framing xslt – amg_amit Oct 10 '18 at 09:16
  • This is the response half part i am getting from client wsdl 233232 234234 2015-12-06 2018-11-28 1 – Chris Ryan Oct 10 '18 at 09:36
  • @amg_amit now payload not giving me this abc: but i need that after this abc: anything like pid, number ,issue etc etc first letter should be capital. – Chris Ryan Oct 10 '18 at 09:37
  • Please find my answer, try removing payload and replace it with xslt mediator – amg_amit Oct 10 '18 at 10:15

1 Answers1

0

Replace payload mediator with xslt mediator .

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:strip-space elements="*"/>
    <xsl:output method="text" indent="yes" media-type="application/json" encoding="UTF-8"/>
    <xsl:template match="/">        
        {
        Body :{

        <xsl:for-each select="//*[local-name()='pid']">

            Result:<xsl:value-of select="result"/>
            IdNumber:<xsl:value-of select="idNumber"/>

        </xsl:for-each>

        }

        }

    </xsl:template>

</xsl:stylesheet>

Once this is done then you need to use property mediator so that the payload is still in json.

 <property name="messageType" scope="default" type="STRING" value="application/json"/>
    <property name="contentType" scope="default" type="STRING" value="application/json"/>
amg_amit
  • 495
  • 1
  • 3
  • 9