Storing strings and integers in one GWT array

It seems like it should be relatively simple, but apparently not much. I can't figure out how to store strings and integers in an array in GWT. What type of data are you using? If I use JsArrayString it outputs IllegalArgumentException

when retrieving the index containing the number. I obviously cannot use JsArrayInteger (I have strings). JsArray requires a type that I have no idea what to use (if it can be used), I tried String

it but get the same results.

The data retrieved from the script page has no way to distinguish between strings and ints (ColdFusion).

0


a source to share


4 answers


Currently, GWT does not have the ability to parse an array structure that contains two different data types, unless in strict JSON form (not as part of the JSON structure in an array passed from ColdFusion).



0


a source


It is now possible using JsArrayMixed

.



+1


a source


I think you can use Object as your type. You will need to put your primitives (int) in the Integer class if it doesn't do it automatically for you. You will also have to do some type checking after you grab what's in the array.

0


a source


It's a little awkward, but you can always make some rough definitions of whether a given value is an int or a string:

<cfset val1="one">
<cfset val2="1">
<cfif int(val(val1)) eq val1>int<cfelse>string</cfif>
<br />
<cfif int(val(val2)) eq val2>int<cfelse>string</cfif>

      

This should give you

 string
 int

      

0


a source







All Articles