02-20-2024 12:05 PM - edited 02-20-2024 12:09 PM
Hi,
I have a requirement where in JSON value need to be send as integer instead of string.
Method in groovy script is:
def json = message.getBody(java.lang.String)
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(json)object.issuer.branchCode = object.issuer.branchCode.toDouble().intValue();
Value is branchCode: "0732340"
Output of above groovy is branchCode: 732340
Expected output is : branchCode: 0732340
Please help with changes that can be done in the code or any alternate code which can be used.
Thanks & Regards,
Mayank
Hi,
what sachin_yadav3
proposed will not work. I think he is mixing it up. It's not about to remove leading zeros because that would then work already right now. It's about how to maintain the leading zeros. The answer is actually: it's impossible.
Mathematical, there are no leading zeros. The first integer number 1 is "1" it's not "01" because then it would mathematical not clear actually how many "leading zeros" you have. Is 1 maybe "00001" or is it "00000000000001" or .... etc. So integer numbers by definition do not have any leading zeros, ever.
If you want to keep using the leading zeros, you have to get rid of your code line where you convert it to double and parse it to integer:
object.issuer.branchCode.toDouble().intValue();
this line of coding will always remove the leading zeros. Get rid of the "toDouble().intValue()". And check if you make use of toString() or if leaving it just like it is isn't already fine enough for you.
Best,
Edrilan Berisha
SAP S/4HANA Cloud Financials Development
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Try by defining object as integer i.e. int object =
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
10 | |
10 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.