<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Two edge cases we ran into with the bundled JsonFx parser]]></title><description><![CDATA[<p dir="auto">Hello!<br />
While storing richer JSON documents through CustomEntityService we ran into two<br />
edge cases in the bundled JsonFx parser (Runtime/JsonFx/JsonReader.cs) that we thought<br />
might be worth sharing, in case other Unity developers hit them too.</p>
<p dir="auto"><strong>1. InvalidCastException when an array-of-arrays mixes inner array shapes (Unity/Mono)</strong></p>
<p dir="auto">Passing this document as the dataJson of CustomEntityService.CreateEntity throws<br />
before the request is even sent:</p>
<pre><code>{ "p": [ [ {"x": 1} ], [] ] }
</code></pre>
<p dir="auto">Also reproduces when the second inner array is all nulls instead of empty.<br />
ReadArray infers a dictionary-array type from the first inner array, then upgrades<br />
arrayItemType to object-array on the mismatched one, and the final<br />
ArrayList.ToArray call throws under Mono's Array.Copy.<br />
A small fallback resolved it for us — wrapping that ToArray call in try/catch and<br />
falling back to the plain object-array ToArray.</p>
<p dir="auto"><strong>2. Integers with 19+ digits (18+ when negative) silently lose precision</strong></p>
<p dir="auto">ReadNumber routes integers with precision of 19 or more to Double.Parse, so a value<br />
like long.MaxValue (9223372036854775807) becomes 9.223372036854776E18 with no error.<br />
Note that precision includes the minus sign, so negative 18-digit integers take the<br />
double path as well. This range is easier to hit than it may look — snowflake-style<br />
IDs (Discord, Twitter/X) are 18-19 digit integers, and long-running idle-game<br />
currencies get there too.</p>
<p dir="auto">What worked for us was raising the threshold to "precision &lt; 29":</p>
<ul>
<li>The integer path already parses through Decimal.Parse, so only the boundary changes.</li>
<li>28 digits is the largest length Decimal.Parse can always hold exactly<br />
(decimal.MaxValue is about 7.9e28, a 29-digit number, so some 29-digit values<br />
would overflow — hence 29 is the widest safe boundary).</li>
<li>Since precision counts the sign, negative values are effectively capped at 27<br />
digits — still comfortably covering the full long range.</li>
<li>Values that fit in long still come back as long; 20-28 digit values fall through<br />
to decimal, which JsonWriter already emits as a quoted string when it exceeds<br />
IEEE754 range — so precision is preserved end to end.</li>
<li>29+ digit integers keep the existing double behavior.</li>
</ul>
<p dir="auto">We're currently carrying both changes as local patches.</p>
<p dir="auto">Thank you!</p>
]]></description><link>https://forums.getbraincloud.com/topic/378/two-edge-cases-we-ran-into-with-the-bundled-jsonfx-parser</link><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Aug 2026 22:38:12 GMT</lastBuildDate><atom:link href="https://forums.getbraincloud.com/topic/378.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 Aug 2026 08:49:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Two edge cases we ran into with the bundled JsonFx parser on Thu, 06 Aug 2026 16:11:45 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for letting us know and your own solutions! We'll see if we can patch this into the JsonFx library we're using for future versions of brainCloud to avoid these edge cases.</p>
]]></description><link>https://forums.getbraincloud.com/post/1380</link><guid isPermaLink="true">https://forums.getbraincloud.com/post/1380</guid><dc:creator><![CDATA[Michael Costa]]></dc:creator><pubDate>Thu, 06 Aug 2026 16:11:45 GMT</pubDate></item></channel></rss>