jrudolph/json-lenses

java.lang.IndexOutOfBoundsException: Too little elements in array

analytically opened this issue · 3 comments

json-lenses fails with the following JSON:

{"parties": {
    "@size": "4",
    "organisation": [
        {
            "id": "19529848",
            "contacts": {
                "address": {
                    "id": "36692152",
                    "street": "Winchester Road",
                    "city": "Leicester",
                    "state": "Leicestershire",
                    "zip": "LE8 5PR",
                    "country": "United Kingdom"
                },
                "email": {
                    "id": "38472610",
                    "emailAddress": "admin@countesthorpe.leics.sch.uk"
                },
                "phone": {
                    "id": "36692153",
                    "type": "Work",
                    "phoneNumber": "0116 2771555"
                },
                "website": [
                    {
                        "id": "36692154",
                        "webAddress": "01162771555",
                        "webService": "SKYPE",
                        "url": "skype:01162771555"
                    },
                    {
                        "id": "36692155",
                        "webAddress": "http:\/\/www.countesthorpe.leics.sch.uk\/",
                        "webService": "URL",
                        "url": "http:\/\/www.countesthorpe.leics.sch.uk\/"
                    },
                    {
                        "id": "44805492",
                        "webAddress": "countesthorpecc",
                        "webService": "TWITTER",
                        "url": "http:\/\/twitter.com\/countesthorpecc"
                    }
                ]
            },
            "pictureURL": "https:\/\/facehub.appspot.com\/twitter\/countesthorpecc?size=70",
            "createdOn": "2012-01-26T17:02:20Z",
            "updatedOn": "2012-04-22T21:42:21Z",
            "name": "Countesthorpe Community College"
        },
        {
            "id": "19529389",
            "contacts": {
                "address": {
                    "id": "36690382",
                    "street": "Roman Road",
                    "city": "Stockbridge",
                    "state": "Hampshire",
                    "zip": "SO20 6HA",
                    "country": "United Kingdom"
                },
                "email": {
                    "id": "42953581",
                    "emailAddress": "test.valley@testvalley.hants.sch.uk"
                },
                "phone": {
                    "id": "36690383",
                    "type": "Work",
                    "phoneNumber": "01264 810555"
                },
                "website": [
                    {
                        "id": "36690384",
                        "webAddress": "01264810555",
                        "webService": "SKYPE",
                        "url": "skype:01264810555"
                    },
                    {
                        "id": "36690385",
                        "webAddress": "http:\/\/www.testvalley.hants.sch.uk",
                        "webService": "URL",
                        "url": "http:\/\/www.testvalley.hants.sch.uk"
                    },
                    {
                        "id": "45433587",
                        "webAddress": "testvalleysch",
                        "webService": "TWITTER",
                        "url": "http:\/\/twitter.com\/testvalleysch"
                    }
                ]
            },
            "pictureURL": "https:\/\/facehub.appspot.com\/twitter\/testvalleysch?size=70",
            "createdOn": "2012-01-26T16:55:30Z",
            "updatedOn": "2012-05-01T14:37:19Z",
            "name": "Test Valley School"
        },
        {
            "id": "19529442",
            "contacts": {
                "address": {
                    "id": "36690619",
                    "street": "Micheldever Road",
                    "city": "Whitchurch",
                    "state": "Hampshire",
                    "zip": "RG28 7JF",
                    "country": "United Kingdom"
                },
                "email": {
                    "id": "38202053",
                    "emailAddress": "adminoffice@testbourne.hants.sch.uk"
                },
                "phone": {
                    "id": "36690621",
                    "type": "Work",
                    "phoneNumber": "01256 892061"
                },
                "website": [
                    {
                        "id": "36690622",
                        "webAddress": "01256892061",
                        "webService": "SKYPE",
                        "url": "skype:01256892061"
                    },
                    {
                        "id": "36690623",
                        "webAddress": "http:\/\/www.testbourne.hants.sch.uk",
                        "webService": "URL",
                        "url": "http:\/\/www.testbourne.hants.sch.uk"
                    }
                ]
            },
            "pictureURL": "https:\/\/d365sd3k9yw37.cloudfront.net\/a\/1374761982\/theme\/default\/images\/org_avatar_70.png",
            "createdOn": "2012-01-26T16:56:25Z",
            "updatedOn": "2012-03-28T07:49:50Z",
            "name": "Testbourne Community School"
        },
        {
            "id": "19532674",
            "contacts": {
                "address": {
                    "id": "36705515",
                    "street": "Testwood Lane",
                    "city": "Southampton",
                    "state": "Hampshire",
                    "zip": "SO40 3ZW",
                    "country": "United Kingdom"
                },
                "email": {
                    "id": "49311759",
                    "emailAddress": "information@testwood.hants.sch.uk"
                },
                "phone": {
                    "id": "36705516",
                    "type": "Work",
                    "phoneNumber": "023 80862146"
                },
                "website": [
                    {
                        "id": "36705517",
                        "webAddress": "02380862146",
                        "webService": "SKYPE",
                        "url": "skype:02380862146"
                    },
                    {
                        "id": "36705519",
                        "webAddress": "http:\/\/www.testwood.hants.sch.uk",
                        "webService": "URL",
                        "url": "http:\/\/www.testwood.hants.sch.uk"
                    }
                ]
            },
            "pictureURL": "https:\/\/d365sd3k9yw37.cloudfront.net\/a\/1374761982\/theme\/default\/images\/org_avatar_70.png",
            "createdOn": "2012-01-26T17:29:34Z",
            "updatedOn": "2012-06-20T09:10:42Z",
            "name": "Testwood Sports College"
        }
    ]
}}

Trace:

size: 4 index: 4
    at spray.json.lenses.package$GetOrThrow.getOrThrow(package.scala:24) ~[json-lenses_2.10-0.5.3.jar:0.5.3]
    at spray.json.lenses.LensImpl.get(Lens.scala:33) ~[json-lenses_2.10-0.5.3.jar:0.5.3]
    at spray.json.lenses.ExtraImplicits$RichJsValue$class.extract(ExtraImplicits.scala:16) ~[json-lenses_2.10-0.5.3.jar:0.5.3]
    at spray.json.lenses.ExtraImplicits$$anon$1.extract(ExtraImplicits.scala:28) ~[json-lenses_2.10-0.5.3.jar:0.5.3]
    at uk.co.coen.ciscoipphonedir.CapsuleCRMCiscoIPPhoneDirectoryService$$anonfun$receive$1$$anonfun$applyOrElse$1$$anonfun$2.apply(CapsuleCRMCiscoIPPhoneDirectoryService.scala:117) ~[classes/:na]
    at uk.co.coen.ciscoipphonedir.CapsuleCRMCiscoIPPhoneDirectoryService$$anonfun$receive$1$$anonfun$applyOrElse$1$$anonfun$2.apply(CapsuleCRMCiscoIPPhoneDirectoryService.scala:117) ~[classes/:na]
    at scala.collection.TraversableLike$WithFilter$$anonfun$map$2.apply(TraversableLike.scala:722) ~[scala-library.jar:0.12.0]
    at scala.collection.immutable.Range.foreach(Range.scala:141) ~[scala-library.jar:0.12.0]
    at scala.collection.TraversableLike$WithFilter.map(TraversableLike.scala:721) ~[scala-library.jar:0.12.0]

@analytically can you post the lens you tried to use?

Hmm it seems like at first it was a problem with my lens, but now I get:

Caused by: java.lang.RuntimeException: Not a json object: [{"id":"24516063","contacts":{"address":{"id":"46637965","street":"32 College Road","city":"Bristol","zip":"BS8 3JH","country":"United Kingdom"},"email":{"id":"46701743","emailAddress":"recruitment@clifton-college.avon.sch.uk"},"phone":{"id":"46637966","phoneNumber":"0117 3157000"},"website":[{"id":"46637967","webAddress":"http://www.cliftoncollegeuk.com","webService":"URL","url":"http://www.cliftoncollegeuk.com"},{"id":"46656852","webAddress":"01173157000","webService":"SKYPE","url":"skype:01173157000"}]},"pictureURL":"https://d365sd3k9yw37.cloudfront.net/a/1374761982/theme/default/images/org_avatar_70.png","createdOn":"2012-05-17T11:05:03Z","updatedOn":"2013-05-23T11:51:56Z","name":"Clifton College"},{"id":"22900853","contacts":{"address":{"id":"43467181","street":"Clifton Road","city":"Newbridge","zip":"EH28 8LQ","country":"United Kingdom"},"email":{"id":"43467182","emailAddress":"office@cliftonhall.org.uk"},"phone":[{"id":"43467184","phoneNumber":"0131 333 1359"},{"id":"43467185","type":"Fax","phoneNumber":"0131 333 4609"}],"website":[{"id":"43467183","webAddress":"www.cliftonhall.org.uk","webService":"URL","url":"http://www.cliftonhall.org.uk"},{"id":"45683794","webAddress":"01313331359","webService":"SKYPE","url":"skype:01313331359"}]},"pictureURL":"https://d365sd3k9yw37.cloudfront.net/a/1374761982/theme/default/images/org_avatar_70.png","createdOn":"2012-04-07T12:26:13Z","updatedOn":"2012-05-03T16:16:15Z","name":"Clifton Hall School"},{"id":"24516065","contacts":{"address":{"id":"46637968","street":"College Road","city":"Bristol","zip":"BS8 3JD","country":"United Kingdom"},"email":{"id":"46701766","emailAddress":"enquiries@cliftonhigh.bristol.sch.uk"},"phone":{"id":"46637969","phoneNumber":"0117 9730201"},"website":[{"id":"46637970","webAddress":"http://www.cliftonhigh.bristol.sch.uk","webService":"URL","url":"http://www.cliftonhigh.bristol.sch.uk"},{"id":"46656853","webAddress":"01179730201","webService":"SKYPE","url":"skype:01179730201"}]},"pictureURL":"https://d365sd3k9yw37.cloudfront.net/a/1374761982/theme/default/images/org_avatar_70.png","createdOn":"2012-05-17T11:05:04Z","updatedOn":"2012-05-17T16:43:46Z","name":"Clifton High School"},{"id":"24517060","contacts":{"address":{"id":"46639504","street":"70 Orchard Road","city":"Lytham St Annes","zip":"FY8 1PJ","country":"United Kingdom"},"phone":{"id":"46639505","phoneNumber":"01253 725815"},"website":[{"id":"46639506","webAddress":"http://www.google.co.uk/search?as_q=Clifton Tutorial Centre Lytham St Annes","webService":"URL","url":"http://www.google.co.uk/search?as_q=Clifton Tutorial Centre Lytham St Annes"},{"id":"46656854","webAddress":"01253725815","webService":"SKYPE","url":"skype:01253725815"}]},"pictureURL":"https://d365sd3k9yw37.cloudfront.net/a/1374761982/theme/default/images/org_avatar_70.png","createdOn":"2012-05-17T11:13:41Z","updatedOn":"2012-05-17T13:29:56Z","name":"Clifton Tutorial Centre"},{"id":"19528702","contacts":{"address":{"id":"36687527","street":"Middle Lane","city":"Rotherham","state":"South Yorkshire","zip":"S65 2SN","country":"United Kingdom"},"email":{"id":"45402878","emailAddress":"ccsadmin@rgfl.org"},"phone":{"id":"36687528","type":"Work","phoneNumber":"01709 515005"},"website":[{"id":"36687529","webAddress":"01709515005","webService":"SKYPE","url":"skype:01709515005"},{"id":"36687530","webAddress":"http://www.cliftonclc.org.uk","webService":"URL","url":"http://www.cliftonclc.org.uk"}]},"pictureURL":"https://d365sd3k9yw37.cloudfront.net/a/1374761982/theme/default/images/org_avatar_70.png","createdOn":"2012-01-26T16:42:40Z","updatedOn":"2012-05-01T07:26:20Z","name":"Clifton: A Community Arts School"},{"id":"24516718","contacts":{"address":{"id":"46638963","street":"Clifton","city":"York","zip":"YO30 6AB","country":"United Kingdom"},"phone":{"id":"46638964","phoneNumber":"01904 527300"},"website":[{"id":"46638965","webAddress":"http://www.google.co.uk/search?as_q=St Peter's School (Inc St Olaves and Clifton Pre-Prep) York","webService":"URL","url":"http://www.google.co.uk/search?as_q=St Peter's School (Inc St Olaves and Clifton Pre-Prep) York"},{"id":"46657393","webAddress":"01904527300","webService":"SKYPE","url":"skype:01904527300"}]},"pictureURL":"https://d365sd3k9yw37.cloudfront.net/a/1374761982/theme/default/images/org_avatar_70.png","createdOn":"2012-05-17T11:10:35Z","updatedOn":"2012-05-17T13:32:17Z","name":"St Peter's School (Inc St Olaves and Clifton Pre-Prep)"}]

While this is valid json

Never mind, it's working now. I guess it's me learning json lenses.