I am trying to parse the xml and reading a big number value from the xml . I want to treat the number value as String in parsing but some reason i am getting a different number after parsing the xml . I am trying to make a json file from the xml . Freemarker is latest version.
My sample code is like below
<LOAN_IDENTIFIERS>
<LOAN_IDENTIFIER>
<MINIdentifier>999910700212884131</MINIdentifier>
</LOAN_IDENTIFIER>
</LOAN_IDENTIFIERS>
Sample Code
<#assign IDENTIFIER = LOAN[0][".//D:LOAN_IDENTIFIERS/.//D:LOAN_IDENTIFIER"]>
MtgId : ${fix(LOAN_IDENTIFIER)}
<#function fix arr>
<#list arr as m>
{
<#assign field = m[".//D:MINIdentifier"]!'null'>
<#if field != 'null' >
<#return field>
</#if>
}
</#list>
</#function>
Output
"MtgId ": 999910700212884096
Expected output is :
"MtgId ": 999910700212884131
But it is a string; FreeMarker won't convert it to number automatically. (Even when it does, it uses BigDecimal
-s by default, so there's no precision loss.) Also, to me, it returns 999910700212884131.
Update: As you generate JSON (or maybe JavaScript?), while the number will be there correctly in the output of FreeMarker, sometimes the side that will later read the JSON can't handle big numbers without rounding errors. Or it wants a string there anyway, in which case output quotation marks around it.