[ 
https://issues.apache.org/jira/browse/GROOVY-7630?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15014159#comment-15014159
 ] 

John Wagenleitner commented on GROOVY-7630:
-------------------------------------------

I took a quick look at Jackson and Gson (and a few others) to see how they 
handle lenient parsing [1].  I couldn't find any settings in Jackson that 
allowed a value such as {{1a}} to parse successfully.  Gson (lenient by 
default) parsed {{1a}} as a string instead of treating like like a number.  I 
tried the JSON5 (javascript) library since it's supposed to be pretty relaxed 
and it failed to parse.

For the LAX parser, it might be good to emulate Gson's approach of treating it 
as a string.  Other option would be to allow it to parse but fail on access of 
the field.

[1] 
https://github.com/jwagenleitner/testing-groovy/tree/7cd75a374dbacfaf0ecc07e70f2a19bc3c3034a2/GROOVY7630/scripts

> JsonSlurper LAX parser with invalid number
> ------------------------------------------
>
>                 Key: GROOVY-7630
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7630
>             Project: Groovy
>          Issue Type: Bug
>          Components: JSON
>    Affects Versions: 2.4.5
>         Environment: DISTRIB_ID=Ubuntu
> DISTRIB_RELEASE=14.10
> DISTRIB_CODENAME=utopic
> DISTRIB_DESCRIPTION="Ubuntu 14.10"
> Linux 3.16.0-44-generic x86_64
>            Reporter: Alan Hengle
>            Priority: Minor
>
> The JsonSlurper LAX parser parses an invalid number incorrectly:
> {code:title=Example.java|borderStyle=solid}
> import groovy.json.*
> def obj = new JsonSlurper().setType(JsonParserType.LAX).parseText('{ "num": 
> 1a}')
> println "1a: num = ${obj.num}"
> println "1a: type is " + obj.num.class.name
> obj = new JsonSlurper().setType(JsonParserType.LAX).parseText('{ "num": 1A}')
> println "1A: num = ${obj.num}"
> println "1A: type is " + obj.num.class.name
> {code}
> produces:
> 1a: num = 59
> 1a: type is java.lang.Integer
> 1A: num = 27
> 1A: type is java.lang.Integer
> It seems like the parser should fail this as an invalid number, though one 
> could argue the LAX parser could interpret it as hex 1a, but neither is being 
> done.  Valid numbers are of course parsed correctly.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to