Jump to content
Server Maintenance This Week. ×

JSON functions seem to fail


This topic is 2117 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

Screen Shot 2018-07-03 at 14.21.35.png

 

BUT it does work all the way back in 4.42 and FM15

 

Edited by john renfrew
Link to comment
Share on other sites

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", trueshould 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 by paja
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

@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.

361165687_ScreenShot2018-07-09at15_27_43.png.199238de69d4e74bd0670a074dc7db95.png

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 by marek
Link to comment
Share on other sites

This topic is 2117 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.