john renfrew Posted July 3, 2018 Posted July 3, 2018 (edited) import groovy.json.JsonOutput class Person { String name } def result = JsonOutput.toJson(new Person(name: 'John')) This 'should just work' - this is Groovy 2.4.0 Mac 10.12.6 Scriptmaster 5.07 up to 5.1 all fail with this Ideas on a postcard please...I BUT it does work all the way back in 4.42 and FM15 Edited July 3, 2018 by john renfrew
paja Posted July 4, 2018 Posted July 4, 2018 (edited) Hi John, this was a compatibility issue in combination with Java 9 and is fixed since Groovy 2.4.6. You ran into it since Scriptmaster on OSX ships with Java 9 now... System.setProperty("groovy.json.faststringutils.disable", true) should work, but I have no way to test it, as I'm on Windows (Java 8 ) at the moment. For reference see: https://issues.apache.org/jira/browse/GROOVY-7716 Edited July 4, 2018 by paja
john renfrew Posted July 4, 2018 Author Posted July 4, 2018 Thanks Almost certainly the issue line might be == System.properties['groovy.json.faststringutils.disable'] = true it still doesn't fix the problem as it thinks it has no way to convert a [B to a [C
ryan360Works Posted July 5, 2018 Posted July 5, 2018 John, I pm'd you a download link to a build of ScriptMaster that uses Groovy 2.4.10 . After installing it, I ran the code you posted above in a ScriptMaster module and got: Quote {"name":"John"} as the return. Not sure if that is the expected output or if I did something wrong so I wanted to see if you could try and see if this update to Groovy resolved the issue. Please let me know what you find.
marek Posted July 6, 2018 Posted July 6, 2018 Hi, It looks I have the similar problem with Groovy JsonSlurper. It works perfectly in SM 4.42 / FMPA 14 (Mac Os 10.13.5, but also Win10): import groovy.json.*; def slurper = new JsonSlurper() def result = slurper.parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}') return result; properly returns: {person={age=33, name=Guillaume, pets=[dog, cat]}} but in SM 5.1 / FMPA17 throws error: Quote java.util.concurrent.ExecutionException: java.lang.reflect.InvocationTargetException Marek
john renfrew Posted July 6, 2018 Author Posted July 6, 2018 @ryan360Works That works with all my tests... thank you!
marek Posted July 6, 2018 Posted July 6, 2018 Ryan, Could you send me download link sent to John? Maybe it can solve also my problem?
john renfrew Posted July 6, 2018 Author Posted July 6, 2018 @marek that will also be fixed, same issue to do with Java 9 on Mac
marek Posted July 6, 2018 Posted July 6, 2018 Thanks a lot Ryan. Yes, I confirm JsonSluper is working now, but with small, not complicated json strings (like in my previous post - it's improvement. But it hangs on bigger and more complicated json, wich SM4.42 / FMPA14 works with without any problems. I tried to change JsonParserType, but command: parser = new JsonSlurper().setType(JsonParserType.CHARACTER_SOURCE) throws error: java.util.concurrent.ExecutionException: java.lang.reflect.InvocationTargetException The default JsonParserType is CHAR_BUFFER. Do you have any idea how to solve this problem? Marek
john renfrew Posted July 8, 2018 Author Posted July 8, 2018 Marek There was a massive change to Slurper after Groovy 1.8, but having said that from the API docs >> INDEX_OVERLAY should be your parser of choice. CHAR_BUFFER is the parser of choice due to element of least surprise and need to mimic existing Slurper behavior as much as possible. Use CHARACTER_SOURCE for large file parsing. Use LAX if you want to enable relaxed JSON parsing, i.e., allow comments, no quote strings, etc. Use CHAR_BUFFER for a non-fancy but super fast parser. Parser speed in order: INDEX_OVERLAY, LAX, CHAR_BUFFER, CHARACTER_SOURCE. Use Cases: Use LAX for config files as it allows comments. Use INDEX_OVERLAY for REST calls, WebSocket messages, AJAX, inter process communication, etc. Use CHAR_BUFFER if eager parsing of ints, dates, longs, are appealing. Use CHARACTER_SOURCE if you are dealing with large JSON files over 2MB. INDEX_OVERLAY is highly tuned for object deserialization from JSON. Try the other parameters??
marek Posted July 8, 2018 Posted July 8, 2018 John, I saw it in API docs, but any try to change JsonParserType fails (I can't change it to any other). I tried all solutions found in web. Marek
marek Posted July 9, 2018 Posted July 9, 2018 (edited) @John, Thanks a lot for your efforts with my problem. Using below code with 5.001 SM plugin as alone plugin installed in FMPA 17.0.1.48 for Central Europe (delivered by Winsoft not Filemaker directly): import groovy.json.JsonSlurper; parser = new JsonSlurper(); result = parser.parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}'); return result; returns as expected: {person={name=Guillaume, age=33, pets=[dog, cat]}} But code: import groovy.json.JsonSlurper; parser = new JsonSlurper().setType(JsonParserType.CHARACTER_SOURCE); result = parser.parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}'); return result; throws error: java.lang.reflect.InvocationTargetException like in attached picture. The same error with 1-st code (without setType) throws when I try to parse more complicated Json object consists from over 2000 of arrays. The same Json limited to few arrays works OK. This is the reason to try setType, but as you see without success. If you like I can send you by mail 2 files which I'm speaking about (complicated and simplified). @Ryan Do you have any idea what can be the reason why setType works for John but not for me? Best regards, Marek Edited July 9, 2018 by marek
john renfrew Posted July 9, 2018 Author Posted July 9, 2018 what answers do you get from the following?? return GroovySystem.version return System.getProperty('java.version')
marek Posted July 9, 2018 Posted July 9, 2018 John, I sent you my Json files (json part1 is working, json full ... is hanging filemaker) Marek
Recommended Posts
This topic is 2396 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now