Parsing the following JSON input and sending the resulting object to the
console yields the expected results for a JSNI JSON.parse() but yields
incorrect timestamps using a JsInterop JSON.parse() (with correct results
for all other properties). I'm completely at a loss as to why. Any
suggestions?
Input:
{"Contract":"STK:USD:PBA@NYSE","action":"onHistoricalData","bar":"D","bars":[{"close":21.76,"high":21.84,"low":21.38,"open":21.41,"time":1451520000,"volume":3067},{"close":21.56,"high":21.63,"low":21.14,"open":21.37,"time":1451865600,"volume":2565},{"close":21.49,"high":21.57,"low":21.26,"open":21.5,"time":1451952000,"volume":2303}],"callback":4,"metadata":{"noData":false},"t":1482867635,"t0":1451763575,"ticker":"STK:USD:PBA@NYSE"}
JSNI JSON parser:
native static Object parse( String json ) /*-{ return $wnd.JSON.parse( json
); }-*/;
JsInterop JSON parser:
@JsType( isNative = true, namespace = GLOBAL, name = "JSON" )
abstract public class JSON {
native static public <T> T parse( String json );
}
@JsType( isNative = true, namespace = JsPackage.GLOBAL, name = "Object" )
public class Message {
public int callback; // HARD-CODED in conjunction with Service::CALLBACK
}
// json from WebSocket
Window.console.info( parse( json ) );
Message message = JSON.parse( json );
Window.console.debug( message );
console.info:
1. Object
1. Contract:"STK:USD:PBA@NYSE"
2. action:"onHistoricalData"
3. bar:"D"
4. bars:Array[3]
1. 0:Object
1. close:21.76
2. high:21.84
3. low:21.38
4. open:21.41
5. time:1451520000
6. volume:3067
7. __proto__:Object
2. 1:Object
1. close:21.56
2. high:21.63
3. low:21.14
4. open:21.37
5. time:1451865600
6. volume:2565
7. __proto__:Object
3. 2:Object
1. close:21.49
2. high:21.57
3. low:21.26
4. open:21.5
5. time:1451952000
6. volume:2303
7. __proto__:Object
4. length:3
5. __proto__:Array[0]
5. callback:4
6. metadata:Object
1. noData:false
2. __proto__:Object
7. t:1482867635
8. t0:1451763575
9. ticker:"STK:USD:PBA@NYSE"
10. __proto__:Object
console.debug:
1.
1. Object
1. Contract:"STK:USD:PBA@NYSE"
2. action:"onHistoricalData"
3. bar:"D"
4. bars:Array[3]
1. 0:Object
1. close:21.76
2. high:21.84
3. low:21.38
4. open:21.41
5. time:1607400000
6. volume:3067
7. __proto__:Object
2. 1:Object
1. close:21.56
2. high:21.63
3. low:21.14
4. open:21.37
5. time:1607400000
6. volume:2565
7. __proto__:Object
3. 2:Object
1. close:21.49
2. high:21.57
3. low:21.26
4. open:21.5
5. time:1607400000
6. volume:2303
7. __proto__:Object
4. length:3
5. __proto__:Array[0]
5. callback:4
6. metadata:Object
1. noData:false
2. __proto__:Object
7. t:1482867635
8. t0:1451763575
9. ticker:"STK:USD:PBA@NYSE"
10. __proto__:Object
I tested the code in Chrome, Edge, and Safari and each yielded the same
results. Any suggestion as to where things are going awry will be greatly
appreciated.
Dave
--
You received this message because you are subscribed to the Google Groups "GWT
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.